2
我想在tableview单元格中加载自定义视图。 的确,我有一个对象数组,并且我想使用自定义视图在单元格中动态加载内容。 我的目标结构是:具有自定义&dymanic视图的UITableView单元格 - 内容
{ ID = 1; date = "2014-01-06"; n1 = 12; n2 = 3; n3 = 34; n4 = 5; n5 = 44; n6 = 24; report = "<null>"; win = 123443; }
我想dispaly为N1,N2的价值观......在视图和我做了这个方法:
@interface MenuCell : UITableViewCell
@property (nonatomic, strong) BallView *ballView;
@property (nonatomic, strong) IBOutlet UILabel *labelDescription;
@property (nonatomic, strong) IBOutlet UILabel *labelDetails;
@property (nonatomic, strong) IBOutlet UIView *ballsView;
+ (CGFloat)getCellHeight;
我BallView.h
@interface BallView : UIView
@property (nonatomic, strong) IBOutlet UIImageView *imgSelectedBall;
@property (nonatomic, strong) IBOutlet UILabel *labelNo;
@property (nonatomic, strong) IBOutlet UIActivityIndicatorView *spinner;
+ (BallView*)showInView:(UIView*)parrentView xOrigin:(NSInteger)xOriginValue;
@end
我BallView.m
+ (BallView*)showInView:(UIView*)parrentView xOrigin:(NSInteger)xOriginValue {
NSArray* nibViews = [[NSBundle mainBundle] loadNibNamed:@"BallView" owner:self options:nil];
BallView *modal = [nibViews objectAtIndex:0];
modal.frame = CGRectMake(xOriginValue,ball_yOrigin, ball_width, ball_height);
[modal setBackgroundColor:[UIColor greenColor]];
[parrentView addSubview:modal];
return modal; }
在我的UITableView委托方法的ViewController我试图加载的信息以这种方式(我做了1号值的测试):
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"NewsCell";
MenuCell *cell = (MenuCell *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"MenuCell_3" owner:self options:nil];
for (id currentObject in topLevelObjects){
if ([currentObject isKindOfClass:[UITableViewCell class]]){
cell = (MenuCell *) currentObject;
}
}
}
__block TickteObj *obj = [self.dataSourceArray objectAtIndex:indexPath.row];
if (obj){
__block CGFloat leftMark = ball_offSet;
for (int i = 1 ; i<5 ; i++){ //5 = my object has 6 numbers which must be displayed
__block BallView *ballView = [BallView showInView:cell.ballView xOrigin:leftMark];
cell.ballView.labelNo.text = obj.n1;
leftMark+=ball_offSet+ballView.frame.size.width;
}
}
return cell;
}
我需要帮助,我的电池装载值。谢谢 !
要加载哪个值?什么不符合你的要求?或者问题出在其他n个值上(显示'TickteObj'的接口)。 – Wain
我尝试从obj.no1(i = 0来自no1的值,i = 1来自obj.no2的值)显示第一个视图的值。它不表示使用if语句,因为它是可行的在增加不可见的情况下 –