我从来没有为tableView实现自定义单元格,并且对如何继续操作感到困惑。我试图制作一个个性测试应用程序,其中每个问题都在我的tableView的一个单元格中进行表示,每个问题下面有几个按钮,这些按钮将作为对相应问题的回应。我已经成功设置了我的单元格的问题和几个按钮与适当的约束,所以他们不会移动textview。需要帮助设置自定义单元格
我还在属性检查器中将单元格样式设置为自定义。
有人可以帮助我如何设置与我的问题的TextView?我试着制作UITextView的一个属性并将它链接到单元格中的TextView,但随后出现一个错误,说我不允许用IBOutlet填充一个重复出现的单元格。
TestVC.h
#import <UIKit/UIKit.h>
#import "Questions.h"
#import "CustomCell.h"
@interface TestViewController : UIViewController <UITableViewDataSource, UITableViewDelegate>
@property (strong, nonatomic) IBOutlet UITableView *tableView;
@property (strong, nonatomic) IBOutlet UITextView *instructions;
@property (weak, nonatomic) IBOutlet UIButton *results;
//@property (strong, nonatomic) IBOutlet *question;
@property (nonatomic, strong) Questions *survey;
-(IBAction)backPressed:(id)sender;
@end
TestViewController.m
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [survey.questions count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *simpleTableIdentifier = @"QuestionCell";
CustomCell *cell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
/*
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
}
*/
NSString *que = (NSString *)[survey.questions objectAtIndex:indexPath.row];
//UITextView *textView = (UITextView *)[cell viewWithTag: 100];
cell.textView = (UITextView *)[cell viewWithTag: 100];
cell.textView.text = que;
return cell;
}
CustomCell.h
#import <UIKit/UIKit.h>
@interface CustomCell : UITableViewCell
// Variables for questions and answers
@property (weak, nonatomic) IBOutlet UITextView *textView;
@property (weak, nonatomic) IBOutlet UIButton *strongAgree;
@property (weak, nonatomic) IBOutlet UIButton *agree;
@property (weak, nonatomic) IBOutlet UIButton *weakAgree;
@property (weak, nonatomic) IBOutlet UIButton *neutral;
@property (weak, nonatomic) IBOutlet UIButton *strongDisagree;
@property (weak, nonatomic) IBOutlet UIButton *disagree;
@property (weak, nonatomic) IBOutlet UIButton *weakDisagree;
@end
CustomCell.m
#import "CustomCell.h"
@interface CustomCell()
@end
@implementation CustomCell
@synthesize textView;
@synthesize strongAgree;
@synthesize agree;
@synthesize weakAgree;
@synthesize neutral;
@synthesize strongDisagree;
@synthesize disagree;
@synthesize weakDisagree;
@end
我按照你的建议,但我遇到了错误。我发布了我的错误截图并更新了代码 – Talcicio
你知道我在做什么错吗?我不明白错误消息 – Talcicio
更新了我的答案,请告诉我它是否修复了您的问题 – Kujey