我是新來的Objective-C,並在一點..我添加UILabel(Name)
,在UITableViewCell
,當我點擊它UIButton
它顯示了一個alertView有兩個按鈕是和否。當我去是的我必須得到該單元的相應值UIlabel(Name)
,但我不明白該怎麼做? 這是代碼我寫創建UILabel
和UIButton
..iPhone中的UITableViewCell中的UIbutton?
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *[email protected]"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.
}
非常感謝.u讓我度過了一天 – Honey