Đây là vấn đề của tôi: Tôi có nhỏ UITableView
này trong kịch bản của tôi: Set UITableView đại biểu và DataSource
Và đây là mã của tôi:
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
Bây giờ bạn có thể thấy, tôi muốn đặt một cá thể được gọi là myTableDelegate làm Đại biểu và DataSource của myTable.
Đây là Nguồn của lớp 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
tôi thực hiện tất cả các UITableViewDelegate
và UITableViewDataSource
phương pháp mà các nhu cầu ứng dụng. Tại sao nó chỉ sụp đổ trước khi xem xuất hiện ??
Cảm ơn !!
bạn có thể dán các lỗi? – JonLOo
Bạn cũng có thể thêm nhật ký sự cố không? – rishi
Kiểm tra cuộc thảo luận trong chuỗi - http://stackoverflow.com/questions/254354/uitableview-issue-when-using-separate-delegate-datasource – rishi