【发布时间】:2012-10-29 11:22:05
【问题描述】:
我是 Objective-C 的新手,在某个点上被击中 ..我在 UITableViewCell 中添加了一个 UILabel(Name),UIbutton(Cancel),当我点击它时 UIButton 它显示一个带有两个按钮的 alertView是和否。当我选择是时,我必须获得该单元格的相应UIlabel(Name) 值。但我不明白该怎么做?
这是我为创建UILabel 和UIButton 编写的代码..
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier=@"Cell";
UITableViewCell* cell=[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if(cell == nil)
{
cell = [[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]autorelease];
}
NSMutableDictionary *d = (NSMutableDictionary *) [arr objectAtIndex:indexPath.row];
UILabel *name=[[UILabel alloc]initWithFrame:CGRectMake(10, 45, 320,15)];
name .font=[UIFont boldSystemFontOfSize:12];
[name setTextAlignment:UITextAlignmentLeft];
[name setText:[d valueForKey:@"Name"]];
name.tag=112;
[cell addSubview:name];
[name release];
UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
btn.frame = CGRectMake(100.0f, 50.0f, 75.0f, 30.0f);
[btn setTitle:@"Delete Details" forState:UIControlStateNormal];
[cell addSubview:btn];
[btn addTarget:self action:@selector(btnClicked:)
forControlEvents:UIControlEventTouchUpInside];
return cell;
}
- (IBAction)btnClicked:(id)sender
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Are you sure" message:@"You want to delete Details" delegate:self cancelButtonTitle:@"No" otherButtonTitles:@"Yes", nil];
[alert show];
[alert release];
}
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex == 0)
{
[alertView dismissWithClickedButtonIndex:0 animated:YES];
}
else
{
//I have to get the corresponding cells UILabel value.
}
【问题讨论】:
标签: iphone xcode4 uitableview