Iphone 显示组件内的按钮通过字符串连接

Iphone 显示组件内的按钮通过字符串连接,iphone,Iphone,我有一个问题,我想用一个按钮来代替“@”n“即,@“uibutton” 经文目录包含圣经的经文,我需要在经文之间加上一个按钮。我希望你能理解我的问题。请帮我做这件事。 提前感谢。我还没有测试过这个,所以它可能包含一些bug,但应该可以帮助您开始 // set these as members of your class NSMutableArray *_versesLabels; // used for easier access when a button is pr

我有一个问题,我想用一个按钮来代替“@”n“即,@“uibutton”

经文目录包含圣经的经文,我需要在经文之间加上一个按钮。我希望你能理解我的问题。请帮我做这件事。
提前感谢。

我还没有测试过这个,所以它可能包含一些bug,但应该可以帮助您开始

    // set these as members of your class
NSMutableArray *_versesLabels;          // used for easier access when a button is pressed
NSMutableArray *_versesButtons;
/*IBOutlet */UIScrollView *_scrollView;

    // your initialization/loading method
// <..set up _scrollView as you wish>
int labelWidth = 300; // change this as you wish
int buttonWidth = 100, buttonHeight=30;
int padding = 5;      // space between labels/buttons from the scrollView
BibleIphoneAppDelegate *appDelegate = (BibleIphoneAppDelegate *)[[UIApplication sharedApplication] delegate];
NSArray *allVerses = [appDelegate.biblearray valueForKey:@"verseNumber"];
int currentY = padding;
for(int i=0; i<[allVerses count]; i++){
        // create and place the label
    UILabel *lbl = [[UILabel alloc] init];
    lbl.text = [allVerses objectAtIndex:i];
    // <..customize the label - fonts, colors etc>
    lbl.numberOfLines = 0;  // in case you have verses that don't fit in a single line
    CGSize size = [lbl.text sizeWithFont:lbl.font constrainedToSize:CGSizeMake(labelWidth, 500)];
    lbl.frame = CGRectMake(0, currentY, labelWidth, size.height);
    [_scrollView addSubView:lbl];
    [_versesLabels addObject:lbl];
    [lbl release];
    currentY=currentY + lbl.frame.size.height + padding;
        // create and place the button
    UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(0, currentY, buttonWidth, buttonHeight)];
    btn.tag = i;
    // <..customize the button - fonts, colors etc>
    [btn addTarget:self action:@selector(pressVerse:) event:UIEventTouchUpInside];
    [_scrollView addSubView:btn];
    [_versesButtons addObject:btn];
    [btn release];
    currentY=currentY + btn.frame.size.height + padding;
}
[_scrollView setContentSize:CGSizeMake(_scrollView.frame.size.width, currentY)];


-(void)pressVerse:(UIButton *)b{
    verseIndex = b.tag;
    UILabel *verseLabel = [_verseLabels objectAtIndex:verseIndex];
    // <..do whatever you want when a button is pressed>
}
//将它们设置为类的成员
NSMutableArray*_vssesLabels;//用于在按下按钮时更容易访问
NSMutableArray*_vs.按钮;
/*IBOutlet*/UIScrollView*\u scrollView;
//您的初始化/加载方法
// 
int labelWidth=300;//你想怎么改就怎么改
int buttonWidth=100,buttonHeight=30;
int padding=5;//滚动视图中标签/按钮之间的间距
BibleIphoneAppDelegate*appDelegate=(BibleIphoneAppDelegate*)[[UIApplication sharedApplication]委托];
NSArray*allVerses=[appDelegate.biblearray valueForKey:@“verseNumber”];
int currentY=填充;

对于(int i=0;iIt不是这样工作的,
componentsJoinedByString:
返回一个
NSString*
。您需要手动创建和添加按钮。我建议使用
uicrollview
并将每个韵文添加到一个单独的
UILabel
,然后在每个标签后添加一个
UIButton
。您必须计算您可以在scrollview中添加每个标签和按钮,并相应地设置scrollview内容大小。@babbidi您可以详细解释吗?请。如果您想在诗句之间添加按钮,您应该使用标签而不是textview。textview也可以这样做,但这会更难。正如我提到的,我还没有测试它,所以它有some bug。它也不完整(例如,您必须设置scrollview)。如果您遇到任何其他错误,我相信您可以通过简单的搜索在internet上找到它们。对于touchupinside错误,请使用
UIControlEventTouchUpInside
。您正在设置按钮吗?在
/
上,您应该设置按钮标题,自定义其外观等。(例如:
[btn setTitle:@“Button”For State:UIControlStateNormal]
)。在这种情况下,您需要将它们放置在表格视图中。对于每一节,您需要创建一个带有标签和按钮的
UITableViewCell
(或者您可以使用带有标签和公开按钮的默认单元格,或者不带按钮的默认单元格,在按下时进行操作).仍有大量内存用于31000节,因此您可能需要使用分页。您可以自定义表格,使其不会分隔单元格。
    // set these as members of your class
NSMutableArray *_versesLabels;          // used for easier access when a button is pressed
NSMutableArray *_versesButtons;
/*IBOutlet */UIScrollView *_scrollView;

    // your initialization/loading method
// <..set up _scrollView as you wish>
int labelWidth = 300; // change this as you wish
int buttonWidth = 100, buttonHeight=30;
int padding = 5;      // space between labels/buttons from the scrollView
BibleIphoneAppDelegate *appDelegate = (BibleIphoneAppDelegate *)[[UIApplication sharedApplication] delegate];
NSArray *allVerses = [appDelegate.biblearray valueForKey:@"verseNumber"];
int currentY = padding;
for(int i=0; i<[allVerses count]; i++){
        // create and place the label
    UILabel *lbl = [[UILabel alloc] init];
    lbl.text = [allVerses objectAtIndex:i];
    // <..customize the label - fonts, colors etc>
    lbl.numberOfLines = 0;  // in case you have verses that don't fit in a single line
    CGSize size = [lbl.text sizeWithFont:lbl.font constrainedToSize:CGSizeMake(labelWidth, 500)];
    lbl.frame = CGRectMake(0, currentY, labelWidth, size.height);
    [_scrollView addSubView:lbl];
    [_versesLabels addObject:lbl];
    [lbl release];
    currentY=currentY + lbl.frame.size.height + padding;
        // create and place the button
    UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(0, currentY, buttonWidth, buttonHeight)];
    btn.tag = i;
    // <..customize the button - fonts, colors etc>
    [btn addTarget:self action:@selector(pressVerse:) event:UIEventTouchUpInside];
    [_scrollView addSubView:btn];
    [_versesButtons addObject:btn];
    [btn release];
    currentY=currentY + btn.frame.size.height + padding;
}
[_scrollView setContentSize:CGSizeMake(_scrollView.frame.size.width, currentY)];


-(void)pressVerse:(UIButton *)b{
    verseIndex = b.tag;
    UILabel *verseLabel = [_verseLabels objectAtIndex:verseIndex];
    // <..do whatever you want when a button is pressed>
}