これは私の問題です:私は私のストーリーボードで、この小さなUITableView
を持って :設定のUITableViewのデリゲートとデータソース
そして、これは私のコードです:
SmallTableViewController.h
#import <UIKit/UIKit.h>
#import "SmallTable.h"
@interface SmallViewController : UIViewController
@property (weak, nonatomic) IBOutlet UITableView *myTable;
@end
SmallTableViewController.m
#import "SmallViewController.h"
@interface SmallViewController()
@end
@implementation SmallViewController
@synthesize myTable = _myTable;
- (void)viewDidLoad
{
SmallTable *myTableDelegate = [[SmallTable alloc] init];
[super viewDidLoad];
[self.myTable setDelegate:myTableDelegate];
[self.myTable setDataSource:myTableDelegate];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
@end
ご覧のとおり、myTableDelegateというインスタンスをDelegateとして設定し、myTableのDataSourceを設定します。
これはSmallTableクラスのソースです。
SmallTable.h
#import <Foundation/Foundation.h>
@interface SmallTable : NSObject <UITableViewDelegate , UITableViewDataSource>
@end
SmallTable.m
@implementation SmallTable
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 0;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return 5;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
// Configure the cell...
cell.textLabel.text = @"Hello there!";
return cell;
}
#pragma mark - Table view delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"Row pressed!!");
}
@end
私はアプリが必要とするすべてUITableViewDelegate
とUITableViewDataSource
方法を実装しました。なぜそれはちょうどビューが表示される前にクラッシュ?
ありがとうございます!
は、あなたがエラーを貼り付けでし設定する必要がありますか? – JonLOo
クラッシュログも追加できますか? – rishi
スレッドで議論を確認する - http://stackoverflow.com/questions/254354/uitableview-issue-when-using-separate-delegate-datasource – rishi