2013-01-05 20 views
0

我想創建一個按鈕單擊事件添加事件,如何在按鈕的點擊中的UITableViewCell在Xcode

此事件應採取文本相應的文本框和打印是作爲先前的小區標籤。

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

static NSString *[email protected]"cellidentifier"; 


UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:cellidentifier]; 

if(cell==nil) 
{ 
    cell=[[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault               reuseIdentifier:cellidentifier]autorelease]; 

} 

if((indexPath.row%2)==0) 
{ 
    UILabel* lblnames=[[UILabel alloc]initWithFrame:CGRectMake(5,5 ,170 ,25)]; 
    [lblnames setText:[listoffriends objectAtIndex:indexPath.row]]; 
    [lblnames setTag:indexPath.row]; 
    cell.contentView.backgroundColor=[UIColor purpleColor]; 
    [cell.contentView addSubview:lblnames]; 
}  
else 
{  
    UITextField* txtn=[[UITextField alloc]initWithFrame:CGRectMake(5, 5, 150, 25)];   
    txtn.delegate=self; 
    [txtn setTag:indexPath.row]; 
    UIButton*btnclkd=[[UIButton buttonWithType:UIButtonTypeRoundedRect]retain]; 
    btnclkd.frame=CGRectMake(200, 5, 70, 25); 
    [btnclkd setTag:indexPath.row]; 
    [btnclkd setTitle:@"OK" forState:UIControlStateNormal] ; 
    [btnclkd addTarget:self action:@selector(btnok:)forControlEvents:UIControlEventTouchUpInside]; 
    [cell.contentView addSubview:btnclkd]; 
    cell.contentView.backgroundColor=[UIColor lightGrayColor]; 
    [cell.contentView addSubview:txtn]; 
} 
return cell; 
} 


-(void)btnok:(id)sender 
{ 
int tag=([sender tag]); 
NSLog(@"%d",tag); 
}  

回答

0

這可能是你想叫什麼:

- (void)reloadRowsAtIndexPaths:(NSArray *)indexPaths 
       withRowAnimation:(UITableViewRowAnimation)animation 

UITableView你需要問一排,部分或整個表重新加載,以便修改可以在屏幕上得到體現。

相關問題