2012-03-12 3 views
-2

Это код, у меня есть:UITableView сбой на свитке

- (id)init 
{ 
    self = [super initWithStyle:UITableViewStylePlain]; 
    if (self) { 
     //self.tableView.delegate = self; 
    } 
    return self; 
} 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 

    UIColor *wood = [UIColor colorWithPatternImage:[UIImage imageNamed:@"wood_pattern.png"]]; 
    self.view.backgroundColor = wood; 
    self.tableView.separatorColor = [UIColor clearColor]; 
} 

#pragma mark - Table view data source 

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

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
    return 3; 
} 

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

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 
     cell.backgroundView.backgroundColor = [UIColor redColor]; 
    } 

    // Configure the cell... 

    cell.textLabel.text = @"Test"; 

    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; 

    return cell; 
} 

#pragma mark - Table view delegate 

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

} 
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { 
    return 60; 
} 

Когда я прокрутите вниз, а затем обратно в клетку, которая ранее была на экране, аварий приложений. Любые идеи почему?

На боковой ноте .. цвет фона установлен на красный, и хотя я вижу текст, я не вижу цвет фона.

+3

Когда разработчики видят сбой, мы обычно ищем, что говорит журнал сбоев. Без Crash регистрируйте трату нашего времени, пытаясь выяснить, просматривая код. Можете ли вы показать нам журнал сбоев. – 0x8badf00d

+1

Установите цвет ячеек вне оператора if, и вы должны увидеть красный цвет, но мне нужно увидеть ошибку для дальнейшей помощи. – Vikings

+0

У меня возникают непрерывные проблемы с xcode, действующими странно (нежирный nslogs, предполагающий наименее вероятные завершения для мой код, подпрыгивая вверх и вниз, когда я набираю текст, каждый раз, когда я пытаюсь добавить файл и т. д.), и сейчас это не дает мне журналы сбоев. – Andrew

ответ

1

Привяжите UITableView правильно в XIB. и правильный следующий код.

- (void)viewDidLoad { 
    [super viewDidLoad]; 

    self.tableView.separatorColor = [UIColor clearColor]; 
} 

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

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 
    return 3; 
} 

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

    static NSString *CellIdentifier = @"Cell"; 

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

    } 
    cell.contentView.backgroundColor = [UIColor redColor]; 
    cell.textLabel.text = @"Test"; 
    cell.textLabel.backgroundColor = [UIColor clearColor]; 
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; 

    // Configure the cell. 

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