2012-03-10 2 views
0

Получают два предупреждения по этому методу, которые я прокомментировал.Два предупреждения в - (NSInteger) tableView: (UITableView *) tableView indentationLevelForRowAtIndexPath: (NSIndexPath *) метод indexPath

Как это исправить? Код ниже.

Заранее спасибо.

#import "ViewController.h" 

@interface ViewController() 

@end 

@implementation ViewController 
@synthesize listData; 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view, typically from a nib. 
    NSArray *array = [[NSArray alloc] initWithObjects:@"Sleepy", @"Sneezy", @"Bashful", @"Happy", @"Doc", @"Grumpy", @"Dopey", @"Thorin", @"Dorin", @"Nori", @"Ori", @"Balin", @"Dwalin", @"Fili", @"Kili", @"Oin", @"Gloin", @"Bifur", @"Bofur", @"Bombur", nil]; 
    self.listData = array; 
} 

- (void)viewDidUnload 
{ 
    [super viewDidUnload]; 
    // Release any retained subviews of the main view. 
    self.listData = nil; 
} 

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown); 
} 

#pragma mark - 
#pragma mark Table View Data Source Methods 
- (NSInteger)tableView:(UITableView *)tableView 
    numberOfRowsInSection:(NSInteger)section 
{ 
    return [self.listData count]; 
} 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *SimpleTableIdentifier = @"SimpleTableIdentifier"; 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:SimpleTableIdentifier]; 
    if (cell == nil) { 
     cell = [[UITableViewCell alloc] 
       initWithStyle:UITableViewCellStyleDefault 
       reuseIdentifier:SimpleTableIdentifier]; 
    } 

    UIImage *image = [UIImage imageNamed:@"star.png"]; 
    cell.imageView.image = image; 

    NSUInteger row = [indexPath row]; 
    cell.textLabel.text = [listData objectAtIndex:row]; 


    if (row < 7) 
     cell.detailTextLabel.text = @"Mr. Disney"; 
    else 
     cell.detailTextLabel.text = @"Mr.Tolkien"; 

    return cell; 
} 

#pragma mark - 
#pragma mark Table Delegate Methods 

- (NSInteger)tableView:(UITableView *)tableView indentationLevelForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    NSUInteger row = [indexPath row]; 

    if (row == 0) 
    return nil; /* Incompatible pointer to integer conversion returning ‘void *' from a function with result type 'NSInteger' (aka 'int').*/ 

    return indexPath; /* Incompatible pointer to integer conversion returning ‘NSIndexPath*_strong' from a function with result type 'NSInteger' (aka 'int').*/ 
} 

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    NSUInteger row = [indexPath row]; 
    NSString *rowValue = [listData objectAtIndex:row]; 

    NSString *message = [[NSString alloc] 
         initWithFormat:@"You selected %@", rowValue]; 
    UIAlertView *alert = [[UIAlertView alloc] 
          initWithTitle:@"Row selected" 
          message:message 
          delegate:nil 
          cancelButtonTitle:@"Yes I Did" 
          otherButtonTitles: nil]; 
    [alert show]; 
} 



@end 

ответ

4

Функция определяет, что будет возвращать NSInteger, возвращая ноль или NSIndexPath нарушит это обещание. О нас:

NSInteger row = (NSInteger)[IndexPath row]; //casts the NSUInteger to NSInteger 

if (row == 0) 
{ 
    return 0; 
} 

return row; 
Смежные вопросы