English 中文(简体)
• 如何使用与多个纽特州相同的可互换意见?
原标题:How To implement UITableView with multiple buttons in same UITableViewCell?

I want to implement UITableView Where I want to have 3 buttons in each UITableViewCell, I want to assign Tittles to each buttons Dynamically, if am having all titles in title_array say then how can I get the index to an array for giving tittles to each buttons in each UITableViewCell ?

here is my code , which is not working,

- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

   // printf("
cellForRowAtIndexPath
");
    //static NSString *CellIdentifier = @"Cell";

    NSString *CellIdentifier = [NSString stringWithFormat:@"identifier_%d", indexPath.row];
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];


    //if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];

        //cell.textLabel.text=@"Golbal VC";
    int x=50;

    if (indexPath.row == 0) {
        sample = 0;
    }else{
        if (sample == [titles_array count]-1);
        else sample += 2;
    }


    for(int i =0; i <2 ; i++){


        UIButton *btn=[UIButton buttonWithType:UIButtonTypeCustom];
        [btn setFrame:CGRectMake(x,50,300, 300)];
        [btn setBackgroundImage:[UIImage imageNamed:@"Canada.gif"] forState:UIControlStateNormal];
        [btn addTarget:self action:@selector(btnAction:) forControlEvents:UIControlEventTouchUpInside]; 
        [cell.contentView addSubview:btn];


        UILabel *tit_lbl=[[UILabel alloc]initWithFrame:CGRectMake(10,10,280,45)];
        [tit_lbl setText:[titles_array objectAtIndex:sample]];
        [btn addSubview:tit_lbl];
        [tit_lbl release];

        UILabel *src_lbl=[[UILabel alloc]initWithFrame:CGRectMake(10,65,280,25)];
        [src_lbl setText:[source_array objectAtIndex:sample]];
        [btn addSubview:src_lbl];
        [src_lbl release];

        x=x+350;
        /*if(index == [titles_array count]-1)
            break;
        index++;        
        */
    }

  return cell;


}
最佳回答

页: 1 Array with NSDictionary 物体,如果你能够按照牢房中的位置向纽芬兰人提供所有权(例如,你可以使用任何东西来识别你的县)。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];         
    }

    NSDictionary *dict = (NSDictionary*)[titleArray objectAtIndex:indexPath.row]; 

    UILabel *tit_lbl=[[UILabel alloc]initWithFrame:CGRectMake(10,10,280,45)];
    [tit_lbl setText:[dict valueForKey:@"titleLabel"]];
    [btn addSubview:tit_lbl];
    [tit_lbl release];  

    UILabel *src_lbl=[[UILabel alloc]initWithFrame:CGRectMake(10,65,280,25)];
    [src_lbl setText:[dict valueForKey:@"sourceLabel"]];
    [btn addSubview:src_lbl];
    [src_lbl release];   

    return cell;
}

希望会有所助益。

问题回答

您应努力利用这一联系,并相应建立习俗小组,并将三顿子放在你可贵的第XIB号卷宗中...... 这是进行这项工作的最简单方法......并在第十一章B分给每个县分配标记......

  1. http://blog.webscale.co.in/?p=284
  2. http://www.e-string.com/content/custom-uitableviewcells-interface-builder
  3. http://adeem.me/blog/2009/05/30/iphone-sdk-tutorial-part-6-creating-custom-uitableviewcell-using-interface-builder-uitableview/




相关问题
Code sign Error

I have created a new iPhone application.I have two mach machines. I have created the certificate for running application in iPhone in one mac. Can I use the other mac for running the application in ...

ABPersonViewController Usage for displaying contact

Created a View based Project and added a contact to the AddressBook using ABAddressBookRef,ABRecordRef now i wanted to display the added contact ABPersonViewController is the method but how to use in ...

将音频Clips从Peter改为服务器

我不禁要问,那里是否有任何实例表明从Peit向服务器发送音响。 I m不关心电话或SIP风格的解决办法,只是一个简单的袖珍流程......

• 如何将搜查线重新定位?

我正试图把图像放在搜索条左边。 但是,问题始于这里,搜索条线不能重新布署。

热门标签