【发布时间】:2015-12-03 13:34:10
【问题描述】:
我以前从未为 tableView 实现过自定义单元格,并且对如何继续感到困惑。我正在尝试制作一个个性测试应用程序,其中每个问题都表示在我的 tableView 的一个单元格中,并且每个问题下方都有几个按钮,它们将作为对相应问题的响应。我已经设法为我的单元格设置了问题的文本视图和几个具有适当约束的按钮,因此它们不会移动。
我还在属性检查器中将单元格样式设置为自定义。
有人可以帮我解决我的问题如何设置文本视图吗?我尝试创建 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
【问题讨论】:
标签: ios objective-c iphone uitableview custom-cell