如何在故事板中将 属性 tableView 连接到 UITableView

How to connect property tableView to UITableView in storyboard

enter image description here我是 iOS 编程的新手,我正在尝试让 UITableView 显示黑客马拉松的时间表。我似乎无法将我在 .h 文件中定义的 属性 连接到我的 ScheduleViewController 中的表视图。当我将按钮与其关联的 属性 连接起来时,我只需按住控件并拖动蓝线即可将它们连接起来。我能够通过命令设置数据源和委托出口并将它们拖到我的 ScheduleViewController 顶部的圆形符号。我还缺少其他设置吗?

ctrl and drag doesn't work

    #import <UIKit/UIKit.h>
    #include "Weekend.h"

    @interface ScheduleViewController : UIViewController <UITableViewDataSource,
        UITableViewDelegate>

    @property (strong, nonatomic) IBOutlet UITableView *tableView;


    @end



#import "ScheduleViewController.h"

@interface ScheduleViewController ()

@end

@implementation ScheduleViewController {

    NSArray *allWeekendDays;    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.

    //Set up schedule for friday
    Weekend *friday = [[Weekend alloc] init];
    friday.day = @"Friday, March 20th";
    friday.events = @"9:00 PM       Check-In\n"
                     "11:00 PM      Opening Ceremony\n"
                     "11:59 PM      Begin Hacks";

    //Set up schedule for saturday
    Weekend *saturday = [[Weekend alloc] init];
    saturday.day = @"Saturday, March 21st";
    saturday.events = @"2:00 AM     Snack Time\n"
                       "8:00 AM     Breakast\n"
                       "1:00 PM     Lunch\n"
                       "7:30 PM     Dinner\n"
                       "10:00 PM    Nerf-Gun Wars\n";

    //Set up schedule for sunday
    Weekend *sunday = [[Weekend alloc] init];
    sunday.day = @"Sunday, March 22nd";
    sunday.events = @"2:00 AM       Snack Time\n"
                     "6:30 AM       Breaskfast\n"
                     "7:30 AM       End Hacks\n"
                     "8:00 AM       Expo 1\n"
                     "9:00 AM       Expo 2\n"
                     "10:00 AM      Closing Ceremony";

    allWeekendDays = [NSArray arrayWithObjects:friday, saturday, sunday, nil];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    //Defines how many rows will be in my table
    return [allWeekendDays count];
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    //Defines how each individual cell will loook like

    static NSString *simpleTableIdentifier = @"WeekendCell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];

    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
    }

    Weekend *schedule = [allWeekendDays objectAtIndex:indexPath.row];
    cell.textLabel.text = schedule.day;
    cell.detailTextLabel.text = schedule.events;

    return cell;
    //Make a class for weekend days, similar to the president one in the demo
}
@end

按照以下步骤操作,希望对您有所帮助

1- 删除 ScheduleViewController 两个文件(Select 删除引用)。

2- ctrl+shift+k(清理你的项目)

3-然后进入项目目录,再次将SchedularViewController文件拖到项目中。

4- 现在转到故事板并再次尝试重新连接 tableView。