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語句,因爲它是可行的在增加不可見的情況下 –