2011-10-20 192 views
1

我都想只知道....添加按鈕在錶行每個單元.....程序運行時 ,也希望點擊時識別按鈕....添加按鈕

我不寫code..here ....

//---insert individual row into the table view--- 


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

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:[NSString stringWithFormat:@"Cell %i",indexPath.section]]; 

    if (cell == nil) { 

     cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:[NSString stringWithFormat:@"Cell %i",indexPath.section]] autorelease]; 

    } 


    NSLog(@"i am here in table function..........now"); 


    //cell.textLabel.text = [data objectAtIndex: indexPath.row]; 

    search_items *pro = [searchCount objectAtIndex:[indexPath row]]; 

    cell.textLabel.text = pro.s_showroomName; 



    UIButton* aButton = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 

     [aButton setTag:[indexPath row]]; 

     [aButton addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside]; 


    [cell.contentView addSubview:aButton]; 

     return cell; 
} 

-(void)buttonClicked:(UIButton*)sender { 
    int tag = sender.tag; 

///and rest code here..... 

} 

此代碼不能正常工作.... :) 請給我解:)

在此先感謝.....請給我任何教程也..

+0

可能重複http://stackoverflow.com/questions/1802707/detecting-which -uibutton-was-press-in-a-uitableview) – Vladimir

+1

哪個'代碼無法正常工作'。你能看到表格視圖單元格上的按鈕嗎?如果不是,請嘗試將按鈕幀設置爲x = 0,y = 0,w = 100,h = 30。你還可以看到填充的表格(包含文本的表格單元格)嗎? – Sahil

+0

@sahil ....我看到填充表格與文本..我從數據庫使用NSMuttable數組searchCount ...(你是右邊框x = 0,y = 0,w = 100,h = 30)...感謝兄弟 – GauravBoss

回答

1

設置幀爲您的按鈕這樣的..

aButton.frame = CGRectMake(0, 0,150,44); 
的[檢測其中的UIButton在一個UITableView壓](
+0

thanks..again ... Trisha ...只有一行,我的代碼工作正常...... :) – GauravBoss