我有以下方案结构:
-(UITableViewCell *)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
...
...
if(cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:SimpleTableIdentifier] autorelease];
...
...
if(condition)
{
do something;
}
else
{
if(condition)
{
unFollowButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
unFollowButton.frame = CGRectMake(180, 10, 120, 30);
unFollowButton.titleLabel.font = [UIFont systemFontOfSize:12];
unFollowButton.tag = indexPath.row;
unFollowButton.titleLabel.textColor = [UIColor blackColor];
[unFollowButton addTarget:self action:@selector(buttonClicked2:) forControlEvents:UIControlEventTouchUpInside];
NSLog(@"fCheckRowCheck Value in if Condition %@",fCheckRowCheck);
[unFollowButton setTitle:@"UnFollow" forState:UIControlStateNormal];
[cell.contentView addSubview:unFollowButton];
buttonValue = 0;
NSLog(@"buttonValue %d", buttonValue);
}
else
{
followButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
followButton.frame = CGRectMake(180, 10, 120, 30);
followButton.titleLabel.font = [UIFont systemFontOfSize:12];
followButton.tag = indexPath.row;
followButton.titleLabel.textColor = [UIColor blackColor];
[followButton setTitle:@"Follow" forState:UIControlStateNormal];
[followButton addTarget:self action:@selector(buttonClicked1:) forControlEvents:UIControlEventTouchUpInside];
[cell.contentView addSubview:followButton];
buttonValue = 1;
NSLog(@"buttonValue %d", buttonValue);
}
}
}
NSUInteger row = [indexPath row];
cell.textLabel.text = [self.infos objectAtIndex:row];
return cell;
}
- (IBAction)buttonClicked2:(UIButton *)sender
{
NSLog(@"BUTTON_CLICKED");
NSIndexPath *indexPath = [folksFolksTable indexPathForCell:(UITableViewCell*) [[sender superview]superview]];
NSLog(@"[sender tag] is %d", [sender tag]);
....
....
....
//Set up URLConnection tp send information on button click
NSMutableString *postString = [NSMutableString stringWithString:kUnFollowURL];
[postString appendString: [NSString stringWithFormat:@"?%@=%@", kId, [user objectForKey:@"id"] ]];
[postString appendString: [NSString stringWithFormat:@"&%@=%@", kfId, [fId objectForKey:@"fID"] ]];
[postString setString: [postString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
NSLog(@"post string = %@", postString);
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:postString]];
[request setHTTPMethod:@"POST"];
followConnection = [[NSURLConnection alloc] initWithRequest:request delegate:self startImmediately:YES];
NSLog(@"postconnection: %@", followConnection);
//Get Response from server
NSData *dataURL = [NSData dataWithContentsOfURL: [ NSURL URLWithString: postString ]];
NSString *serverOutput = [[NSString alloc] initWithData:dataURL encoding: NSASCIIStringEncoding];
NSLog(@"serverOutput = %@", serverOutput);
//Change the button lable from unfollow to follow
[sender setTitle:@"Follow" forState:UIControlStateNormal];
if([sender tag]==indexPath.row)
{
textField = (UITextField*)[cell viewWithTag:[sender tag]];
NSLog(@"txtF is %@",textField);
textField.hidden=NO;
}
}
- (IBAction)buttonClicked1:(UIButton *)sender
{
similar to buttonClicked 2
}
我需要的是,在标签在运行期间发生变化之后,纽伦应当采取相应的行动。
例如,如果我点击纽州[纽顿标签],那么我就在那个时候就看到了(正在完全是科索沃)的标签。 现在,当我再次用“黄色”标签点击同一纽州时,它就成为例外。
How to go about it. Please help me figure it out ?