我遇到了一些我的 UITableView 没有重新加载的问题,我重做了插座的链接以确保这不是问题。我也尝试过使用 [self table] reloadData] 但这似乎也不起作用。我已经调试了这些问题,但它只是跳过了 reloadData 并且应用程序继续运行,就像代码甚至不存在一样。
我的 .m 文件的顶部,在 ViewDidLoad 中什么也没做
#import "SettingsCourses.h"
@implementation SettingsCourses
@synthesize settingsCourses;
@synthesize Delegate;
@synthesize BackButton;
@synthesize DeleteButton;
@synthesize table;
@synthesize courses;
@synthesize dataHandler;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
dataHandler = [[DataHandler alloc] init];
dataHandler.coursesDelegate = self;
courses = [dataHandler fetchCourses];
NSLog(@"Debug Count: %i", [courses count]);
}
[table reloadData];
return self;
}
- (void) viewWillAppear:(BOOL)animated {
[table reloadData];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if (courses) {
NSLog(@"Count: %i", [courses count]);
return [courses count];
}
else {
NSLog(@"Count: 0");
return 0;
}
}
我的 .h 文件
#import <UIKit/UIKit.h>
#import "dataHandler.h"
@interface SettingsCourses : UIViewController
@property (strong, nonatomic) DataHandler *dataHandler;
@property (strong, nonatomic) NSMutableArray *courses;
@property (strong, nonatomic) IBOutlet UIView *settingsCourses;
@property (nonatomic, strong) id Delegate;
@property (weak, nonatomic) IBOutlet UIButton *BackButton;
@property (weak, nonatomic) IBOutlet UIButton *DeleteButton;
@property (weak, nonatomic) IBOutlet UITableView *table;
- (IBAction)Delete:(id)sender;
- (IBAction)Back:(id)sender;
谢谢你的帮助!