Дело следующее: Я хочу создать UITableView из отдельного класса.UITableView из отдельного класса
В настоящее время я следующее:
// Menu.h
@interface Menu : UITableViewController <UITableViewDelegate, UIAlertViewDelegate> {
UITableView *tableView;
}
@property (nonatomic,retain) NSMutableArray *navigationItems;
- (void)initMenu:(UIView *)view;
@end;
Тогда
// Menu.m
#import <Foundation/Foundation.h>
#import "Menu.h"
@implementation Menu
- (void) initMenu:(UIView *)view {
self.navigationItems = [[NSMutableArray alloc] initWithObjects:@"One",@"Two",@"Three",@"Four",@"Five",@"Six",@"Seven",@"Eight",@"Nine",@"Ten",nil];
UIView *mainmenu=[[UIView alloc]initWithFrame:CGRectMake(0, 50, 320, 420)];
[mainmenu setBackgroundColor:[UIColor yellowColor]];
[view addSubview:mainmenu];
UITableView *menutableView = [[UITableView alloc] initWithFrame:view.bounds style:UITableViewStylePlain];
menutableView.backgroundColor = [UIColor whiteColor];
menutableView.delegate = self;
menutableView.dataSource = self;
[mainmenu addSubview:menutableView];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableViewi cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableViewi dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
cell.textLabel.text = [self.navigationItems objectAtIndex:indexPath.row];
return cell;
}
@end
И в другом файле .m я вызываю метод:
...
#import "Menu.h"
...
- (void)viewDidLoad
{
[super viewDidLoad];
...
Menu *menu = [[Menu alloc] init];
[menu initMenu: self.view];
}
Запуск этого приложения приведет к краху и Xcode выиграл» t дать подробный отчет. Однако, если я совмещаю Menu.m с файлом .m, где я вызываю «initMenu», он не будет разбиваться.
Также, если я прокомментирую menutableView.dataSource = self;
, он будет работать с нашей катастрофой (без строк в таблице, конечно ...).
Опубликовать сообщение об аварии. –
Я получаю только: (lldb) – Rub4
Добавить контрольную точку исключения в xcode и посмотреть, в какой строке она разбивается –