I'm new to objective-C and strucked at a point ..I'm adding a UILabel(Name)
,UIbutton(Cancel)
in UITableViewCell
and when I click on it UIButton
it shows an alertView with two button Yes and No .When I go for Yes I have to get the corresponding UIlabel(Name)
value of that cell.But I could not understand how to do it ?
This is the code Im writing for creating a UILabel
and 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.
}