2016-05-16 3 views
0

次のコードは、URLからデータを取得するためのコードです。私は3行の選択肢の限られたを選択したい。この問題を解決するために私を助けてください。あなたはグローバル変数を持っており、最初にその値を0に設定することができますTIAURLからのUITableViewの行の選択の制限

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { 
    return 1; 
} 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 
    // Return the number of rows in the section. 
    return [self.countriesArr count]; 
} 


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

    NSUInteger row = [indexPath row]; 

    static NSString *MyIdentifier = @"tableCell"; 

    CustomCell *cell = (CustomCell *) [tableView dequeueReusableCellWithIdentifier:MyIdentifier]; 


    if (cell == nil) { 

     NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"CustomCell" owner:self options:nil]; 

     for (id currentObject in topLevelObjects){ 
      if ([currentObject isKindOfClass:[UITableViewCell class]]){ 
       cell = (CustomCell *) currentObject; 

      } 
     } 

    } 

    NSDictionary *thisRow = [self.countriesArr objectAtIndex:row]; 


    if(_WSConstCountryID !=nil && ![_WSConstCountryID isEqual:@"0"] && ![_WSConstCountryID isEqual:@""] && _WSConstCountrySelectedIndex ==row ) 
    { 
     cell .accessoryType=UITableViewCellAccessoryCheckmark; 
    } 
    else { 
     cell .accessoryType=UITableViewCellAccessoryNone; 
    } 

    cell.lblTitle.text = [thisRow objectForKey:_WSColumnCountryName]; 
    NSString *str=[thisRow objectForKey:_WSColumnCountryID]; 
    NSString *stra=_WSConstCountryID; 
    if ([str isEqualToString:stra]) { 
     cell .accessoryType=UITableViewCellAccessoryCheckmark; 
     cell.highlighted=YES; 
    }else 
    { 
     cell .accessoryType=UITableViewCellAccessoryNone; 

    } 


    return cell; 


} 
#pragma mark - 
#pragma mark Table view delegate 

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 


    [tableView deselectRowAtIndexPath:indexPath animated:YES]; 

    NSUInteger row = [indexPath row]; 
    NSDictionary *thisRow=[self.countriesArr objectAtIndex:row]; 
    NSLog(@"%@",[thisRow description]); 


    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; 



    if (cell.accessoryType == UITableViewCellAccessoryNone) 
    { 
     cell.accessoryType = UITableViewCellAccessoryCheckmark; 
    } 
    else 
    { 
     cell.accessoryType = UITableViewCellAccessoryNone; 
    } 

    if(_WSConstCountryID!=nil && ![_WSConstCountryID isEqual:@"0"] && ![_WSConstCountryID isEqual:@""] &&_WSConstCountrySelectedIndex!=row) 
    { 

     UITableViewCell *cell = [tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:_WSConstCountrySelectedIndex inSection:0]]; 


     if (cell != nil) 
     { 
      cell .accessoryType=UITableViewCellAccessoryNone; 
     } 

    } 
    if(cell.accessoryType == UITableViewCellAccessoryCheckmark) 
    { 
     _WSConstCountryID=[thisRow objectForKey:_WSColumnCountryID]; 
     _WSConstCountryName=[thisRow objectForKey:_WSColumnCountryName]; 
     _WSConstCountrySelectedIndex=row ; 
    } 
    else 
    { 
     [email protected]"0"; 
     [email protected]"Select"; 
     _WSConstCountrySelectedIndex=-1 ; 
    } 

    [self.navigationController popViewControllerAnimated:YES]; 

} 

答えて

0

、 増加/選択しました選択を解除したのでで、その値を減らします。値が0〜3の範囲内にあることを確認し、値が3を超えようとしているときに適切なメッセージを表示してください。

関連する問題