簡體   English   中英

單擊另一個視圖控制器中的按鈕時實現原型單元

[英]implement prototype cell when I click a button in another view Controller

我的程序有一個視圖控制器和一個tableView控制器。 我打算每次單擊viewController中的按鈕時,以當前時間升級tableview單元。

ViewController.m

@interface ViewController ()
  @property(nonatomic,strong) Brain* brain;
  @property(nonatomic,readonly)TimeTableController* tableControl;
@end

- (void)viewDidLoad
{
  [super viewDidLoad];
  _brain=[[Brain alloc] init];
  _tableControl=[[TimeTableController alloc] init];
}
- (IBAction)actionTime:(id)sender {
   [self.tableControl.entryTime addObject:[self.brain currentTime]];
}

timeTableController.h

@property (strong, nonatomic) IBOutlet UITableView *timeTable;
@property(nonatomic,strong) NSMutableArray* entryTime;

timeTableController.m

- (void)viewDidLoad
{
  [super viewDidLoad];

  _entryTime=[[NSMutableArray alloc] init];
  _timeTable=[[UITableView alloc] init];


  #pragma mark - Table view data source

 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
 {   if(!_entryTime) return 0;
  else
      return 1;
  }

  - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
 {
   return [_entryTime count];
  }
  - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
 { ...
  self.cell.timeLabel.text = [NSString stringWithFormat:@"%@",[self.entryTime objectAtIndex:[indexPath row]]];
  }
[self.tableControl.timeTable reloadData];
 return cell;
}

但是,當我按下按鈕時,什么也沒發生。 有人可以幫我解決嗎?

你在哪

@property(nonatomic,strong) NSString* timeLabel;

然后,在將標簽放置在位於xib文件中的自定義單元格中之后,不要忘記將其連接到xib文件中。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM