2014-12-11 1 views
1

나는 테이블보기를 사용하고 있고 내 tableview 데이터가 서버에서오고 있음 inboxmodule을 만들고 있는데 테이블 셀 색상을 변경하려고합니다. messagereadflag = 0이면 서버에서 오는 플래그를 기준으로 셀의 회색을 원한다면 메시지 읽기 플래그 = 1이면 사용자가 읽기 및 읽지 않은 메시지를 쉽게 구별 할 수 있도록 선명한 색상을 원합니다. 어떻게 깃발 아래 서버에서 오는 경우가 할 수있는 것은 아래에있는 내있는 tableview 셀 코드 내 대답서버에서 오는 플래그를 기반으로 uitableviewcell의 색상을 변경하는 방법

-(void)inboxmessagesGetSuccess:(FBGenericWebHandler*)handler response:(NSDictionary*)response 
{ 
    [MBProgressHUD hideHUDForView:self.view animated:YES]; 

    NSMutableArray *inboxArray = [[NSMutableArray alloc] init]; 
    NSArray *firstarray=[[[response objectForKey:@"messageResponse"] objectAtIndex:1] objectForKey:@"messages"]; 
    for(NSDictionary *tmp in firstarray) 
    { 
     NSMutableDictionary *messages=[[NSMutableDictionary alloc]init]; 
     [messages setValue:[tmp objectForKey:@"messageId"] forKey:@"messageId"]; 
     [messages setValue:[tmp objectForKey:@"messageDate"] forKey:@"messageDate"]; 
     [messages setValue:[tmp objectForKey:@"messageTime"] forKey:@"messageTime"]; 
     [messages setValue:[tmp objectForKey:@"offerTitle"] forKey:@"offerTitle"]; 
     [messages setValue:[tmp objectForKey:@"messageRead"] forKey:@"messageRead"];// here are coming flags 
     [self.inboxmessagesarray addObject:messages]; 
    } 
    [self.tb reloadData]; 
    } 

입니다 : 친절하게 도움을 사전에

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ 

    static NSString *tableviewidentifier = @"cell"; 
    tablecellTableViewCell *cell= [self.activitiesTableView_ dequeueReusableCellWithIdentifier:tableviewidentifier]; 

    if(cell==nil) 
    { 
     cell = [[tablecellTableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:tableviewidentifier]; 
    }if(indexPath.row == [self tableView:tableView numberOfRowsInSection:indexPath.section] - 1){ 

    } 

    UILabel *valuedate = (UILabel *)[cell viewWithTag:21]; 
    UILabel *msg = (UILabel *)[cell viewWithTag:22]; 
    UILabel *date = (UILabel *)[cell viewWithTag:23]; 
    UILabel *time = (UILabel *)[cell viewWithTag:24]; 
    if([[[self.inboxmessagesarray objectAtIndex:indexPath.row]objectForKey:@"messageRead"] intValue]==0) 
    { 
     cell.backgroundColor=[UIColor grayColor]; 
    } 
    else 
    { 
     cell.backgroundColor=[UIColor clearColor]; 
    } 
    valuedate.text=[[self.inboxmessagesarray objectAtIndex:indexPath.row]objectForKey:@"offerTitle"]; 
    [email protected]"How are you?"; 
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{ 
     NSString *img=[[self.inboxmessagesarray objectAtIndex:indexPath.row]objectForKey:@"offerPhoto"];// here i am getting image path 
     NSURL *url = [NSURL URLWithString:img]; 
     NSData * imageData = [NSData dataWithContentsOfURL:url]; 
     UIImage *image = [UIImage imageWithData:imageData]; 

     dispatch_sync(dispatch_get_main_queue(), ^{ //in main thread update the image 
      cell.imageView.image = image; 
      cell.textLabel.text = @""; //add this update will reflect the changes 
     }); 
    }); 



    date.text=[[self.inboxmessagesarray objectAtIndex:indexPath.row]objectForKey:@"messageDate"]; 
    time.text=[[self.inboxmessagesarray objectAtIndex:indexPath.row]objectForKey:@"messageTime"]; 


    return cell; 
    } 

고맙습니다 :(

+0

사전인가를 만들 태그의 ionary를 key로, 색상 객체를 value로 가져온 다음 서버에서 태그를 가져온 후 사전에서 태그 객체로 색상 객체를 가져옵니다. –

+0

샘플 예제를 제공하겠습니까? –

+0

당신은 내가 그 체크 박스 카운트 전에 누가 대답 했나요? –

답변

2

사용 cell.contentView.backgroundColor 대신 의 cell.backgroundcolor 속성입니다.

cellForRowAtIndexPath 방법

if([[self.inboxmessagesarray objectAtIndex:indexPath.row]objectForKey:@"messageRead"] intValue]==0) 
{ 
    cell.contentView.backgroundColor=[UIColor grayColor]; 
} 
else 
{ 
    cell.contentView.backgroundColor=[UIColor clearColor]; 
} 

이 코드를 시도하거나 를 사용 willDisplayCell 방법 셀을 업데이트 할

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath { 

     if([[self.inboxmessagesarray objectAtIndex:indexPath.row]objectForKey:@"messageRead"] intValue]==0) 
    { 
     cell.backgroundColor=[UIColor grayColor]; 
    } 
    else 
    { 
     cell.backgroundColor=[UIColor clearColor]; 
    } 

} 
+0

또한 btn을 클릭해도 색상을 변경하고 싶지만 btn을 클릭하면 콘텐츠보기도 설정되어 있지만 회색 색상이 표시되지 않습니까? –

1

조건을 추가 in

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ 

플래그 값을 확인합니다.

if([[self.inboxmessagesarray objectAtIndex:indexPath.row]objectForKey:@"messageRead"] intValue]==0) 
    { 
     cell.backgroundColor=[UIColor grayColor]; 
    } 
    else 
    { 
     cell.backgroundColor=[UIColor clearColor]; 
    } 
+0

어디서이 조건을 추가 할 수 있습니까 ??? –

+0

- (UITableViewCell *) tableView : (UITableView *) tableView cellForRowAtIndexPath : (NSIndexPath *) indexPath {셀을 반환하기 전에; –

+0

k 기다려 나는 내가 말할 게다 –

2

사용 jQuery과 대리자 메서드,

-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath { 

if([[self.inboxmessagesarray objectAtIndex:indexPath.row]objectForKey:@"messageRead"] intValue]==0) 
    { 
     cell.backgroundColor=[UIColor grayColor]; 
    } 
    else 
    { 
     cell.backgroundColor=[UIColor clearColor]; 
    } 

} 
관련 문제