iOS - ошибка просмотра таблицы - PullRequest
0 голосов
/ 15 сентября 2011

У меня небольшая проблема с моим первым представлением таблицы, я использую пример, взятый из Интернета, но когда я запускаю код, он выдает сообщение:

2011-09-15 15:58:48.873 fptNew[1710:207] -[UIViewController tableView:numberOfRowsInSection:]: unrecognized selector sent to instance 0x4b3d120
2011-09-15 15:58:48.876 fptNew[1710:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIViewController tableView:numberOfRowsInSection:]: unrecognized selector sent to instance 0x4b3d120'

вот код:

//  familySelect.m
//  fptNew
//
//  Created by Marco on 14/09/11.
//  Copyright 2011 __MyCompanyName__. All rights reserved.

#import "familySelect.h"

@implementation familySelect

@synthesize colorNames;

 // The designated initializer.  Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
/*
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization.
    }
    return self;
}
*/


// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];

    NSLog(@"eseguito");
    self.colorNames = [[NSArray alloc] initWithObjects:@"Red", @"Green", @"Blue", @"Indigo", @"Violet", nil];

    //UILabel *label = (UILabel *)[self.view viewWithTag:111];
    //label.backgroundColor =   [UIColor colorWithRed:0.2f green:0.3f blue:0.4f alpha:0.00000f];

}



- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Overriden to allow any orientation.
    return YES;
}


- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];

    // Release any cached data, images, etc. that aren't in use.
}


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

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

// 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:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    }

    // Configure the cell.
    cell.textLabel.text = [self.colorNames objectAtIndex: [indexPath row]];

    return cell;
}

- (void)dealloc {
    [super dealloc];
}

@end

вот файл .h:

//  familySelect.h
//  fptNew
//
//  Created by Marco on 14/09/11.
//  Copyright 2011 __MyCompanyName__. All rights reserved.

#import <UIKit/UIKit.h>


@interface familySelect : UIViewController 
    <UITableViewDelegate, UITableViewDataSource> {
    NSArray *colorNames;
}

@property (nonatomic, retain) NSArray *colorNames;

@end

и в файле .xib я установил источник данных табличного представления и делегата Владельцу файла (familySelect)

не понимаю, в чем проблема, спасибо за любую помощь

Ответы [ 3 ]

3 голосов
/ 15 сентября 2011

Где находится ваш IBOutlet UITableView * myTableView?

3 голосов
/ 15 сентября 2011

Вам потребуется выполнить следующие подключения в Интерфейсном Разработчике

  • таблица для владельца файла (выберите делегата)
  • таблица владельца файла (выберите источник данных)
  • Владелец файла для просмотра (выберите вид): это соединение устанавливается автоматически
  • Владелец файла для таблицы (выберите tableView)

См. также на этой странице

2 голосов
/ 15 сентября 2011

Кажется, вы передали метод Tableview на View Controller и, следовательно, вылетаете.

 -[UIViewController tableView:numberOfRowsInSection:]

Вы подключили View для VIew Controller к TableView.Вместо этого объявите UITableView и подключите это табличное представление.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...