Questo è il mio problema: ho questo piccolo UITableView
nel mio storyboard: Set UITableView Delegato e DataSource
E questo è il mio codice:
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
Ora come puoi vedere, voglio impostare un'istanza chiamata myTableDelegate come delegato e DataSource di myTable.
Questa è la sorgente della classe 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
ho implementato tutto il metodo UITableViewDelegate
e UITableViewDataSource
che la necessità app. Perché si blocca prima che appaia la vista ??
Grazie !!
Potresti incollare l'errore? – JonLOo
Puoi aggiungere anche i crash log? – rishi
Controlla la discussione nella discussione - http://stackoverflow.com/questions/254354/uitableview-issue-when-using-separate-delegate-datasource – rishi