所以我有2個按鈕用於每個小區,我已設法單獨地標記的表圖。我需要兩個按鈕被按下後才能禁用(投票功能)在哪裏我目前,按鈕在視圖中禁用,並且不會被點擊(儘管字體顏色甚至沒有響應,即使它設置爲UIControlStateDisabled,是另一個不太緊迫的問題)。但是,當我從禁用按鈕的視圖中滾動出來時,他們會再次點擊時觸發該操作。我怎樣才能確保保持這種狀態?我有這將分配的setEnabled基於陣列上的bool數組,但只有一半的作品,它幾乎一樣,如果我看到海誓山盟的最上面的扣子,但是,字體並在這一點上作出迴應。請大家幫忙。(和我很抱歉,不管別人怎麼說,這個網站確實需要重寫它的代碼粘貼的東西,整個4號線的事情是沒有效率可言)UIButtons沒有禁用正確
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:
(NSIndexPath*)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle
reuseIdentifier:CellIdentifier]autorelease];
}
NSDictionary *aTrip = [trips objectAtIndex:[indexPath row]];
cell.textLabel.text =[NSString stringWithFormat:@"%@& *** posted by %@ %@",[aTrip
objectForKey:@"txt"],
[aTrip objectForKey:@"name"], [aTrip
objectForKey:@"time"]];
cell.textLabel.adjustsFontSizeToFitWidth = YES;
cell.textLabel.font = [UIFont systemFontOfSize:12];
cell.textLabel.minimumFontSize = 10;
cell.textLabel.numberOfLines = 4;
cell.textLabel.lineBreakMode = UILineBreakModeWordWrap;
cell.detailTextLabel.text = [aTrip objectForKey:@"name"];
UIButton *upvote =[UIButton buttonWithType:UIButtonTypeCustom];
UIImage *upVoteBack = [UIImage imageNamed:@"arrowup.png"];
upvote.tag = 2*[indexPath row];
NSLog(@"the tag for upbutton is %d",upvote.tag);
[upvote setBackgroundImage:upVoteBack forState:UIControlStateNormal];
upvote.titleLabel.font = [UIFont boldSystemFontOfSize:12.0];
[upvote setTitleColor:[UIColor redColor] forState:UIControlStateDisabled];
[upvote setTitle:[buttonTitles objectAtIndex:[indexPath row]] forState:UIControlStateNormal];
upvote.frame = CGRectMake(250.0f, 40.0f, 25.0f, 25.0f);
[upvote addTarget:self
action:@selector(upvoteaction:)forControlEvents:UIControlEventTouchUpInside];
[upvote retain];
[cell addSubview:upvote];
UIButton *downvote =[UIButton buttonWithType:UIButtonTypeCustom];
UIImage *downVoteBack = [UIImage imageNamed:@"arrowdown.png"];
downvote.titleLabel.font = [UIFont boldSystemFontOfSize:12.0];
[downvote setTitle:[buttonTitles2 objectAtIndex:[indexPath row]]
forState:UIControlStateNormal];
downvote.tag = 2*[indexPath row]+1;
NSLog(@"the tag for downvote is %d",downvote.tag);
[downvote setBackgroundImage:downVoteBack forState:UIControlStateNormal];
downvote.frame = CGRectMake(280.0f, 40.0f, 25.0f, 25.0f);
[downvote addTarget:self
action:@selector(upvoteaction:)forControlEvents:UIControlEventTouchUpInside];
[cell addSubview:downvote];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;
}
-(void) upvoteaction:(id) sender{
NSString *upnumber = @"12";
NSString *downnumber = @"5";
NSString *upordown;
int k;
if([sender tag]%2){
upordown = @"2";
k=-1;
}
else{
k=1;
upordown = @"1";
}
NSLog(@"upordown is %@", upordown);
NSLog(@"sender tag is %d",[sender tag]);
NSIndexPath *indexPath = [self.tableView indexPathForCell:(UITableViewCell *)[sender superview]];
NSDictionary *trip = [trips objectAtIndex:[indexPath row]];
NSString *IDtoUse = [trip objectForKey:@"id"];
IDhold = IDtoUse;
NSString *post =[NSString stringWithFormat:@"id=%@&vote=%@",IDhold, upordown];
NSLog(@"IDhold is %@", IDhold);
NSNumber *wrapped = [NSNumber numberWithBool:NO];
UIButton *button1 = (UIButton *)[[sender superview] viewWithTag:[sender tag]];
button1.enabled = NO;
UIButton *button2 = (UIButton *)[[sender superview] viewWithTag:[sender tag]+k];
button2.enabled = NO;
[buttonTitles replaceObjectAtIndex:[indexPath row] withObject:upnumber];
[buttonTitles2 replaceObjectAtIndex:[indexPath row] withObject:downnumber];
/*
NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];
NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];
[request setURL:[NSURL URLWithString:@"http://livepartyscene.com/tfln.php?"]];
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:postData];
NSError *error;
NSURLResponse *response;
NSData *urlData=[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
NSString *data=[[NSString alloc]initWithData:urlData encoding:NSUTF8StringEncoding];
*/
[self.tableView reloadData];
[IDhold release];
}