그래서 개별적으로 태그를 관리 할 수있는 각 셀에 2 개의 버튼이있는 테이블보기가 있습니다. 나는 하나의 버튼을 눌렀을 때 (UIControlStateDisabled에 대해 설정 한 글꼴 색상이 모두 응답하지 않더라도) 버튼을 사용하지 않도록 설정해야합니다 (투표 기능). 나는 현재 버튼이 보이지 않는 동안 버튼을 사용하지 않고 클릭하지 않습니다. 또 다른 덜 중요한 문제입니다). 그러나 비활성화 된 버튼보기에서 스크롤하여 돌아 왔을 때 클릭 한 상태에서 다시 작업을 시작합니다. 이 상태를 유지하려면 어떻게해야합니까? 배열을 기반으로 setEnabled를 할당하는 bool 배열을 가졌지 만 절반 만 작동합니다. 즉, 서로의 상단에있는 단추를 보는 것처럼 글꼴은이 시점에서 응답합니다. . 도와주세요 나이 감안할 때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];
}