簡體   English   中英

UITableView中的TableCell視圖未出現在模擬器iOS7中

[英]TableCell views in UITableView not appearing in simulator iOS7

我一直在瘋狂地閱讀文檔,試圖解決我的問題,但是我不認為我的問題太難了,我可能會做錯了。 這是我的UIViewController

這是模擬器中的外觀:

圖片圖像

我只需要將填充的單元格真正出現在模擬器中即可。 我已經在.h中使用它設置了數據並委托了源:

@property (weak, nonatomic) IBOutlet UITableView *grTableView;
@property(nonatomic, assign) id<UITableViewDataSource> dataSource;
@property(nonatomic, assign) id<UITableViewDelegate> delegate;

這在.m的viewDidLoad中:

grTableView.dataSource = self;
grTableView.delegate = self;

而且我想用這種方法設置間距(我知道我可以處理約束,但是不確定如何做 ):

-(CGFloat)tableView:(UITableView*)tableView heightForHeaderInSection:(NSInteger)section
{
    if(section == 0)
        return 6;
    return 1.0;
}

-(CGFloat)tableView:(UITableView*)tableView heightForFooterInSection:(NSInteger)section
{
    return 5.0;
}

-(UIView*)tableView:(UITableView*)tableView viewForHeaderInSection:(NSInteger)section
{
    return [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];
}

-(UIView*)tableView:(UITableView*)tableView viewForFooterInSection:(NSInteger)section
{
    return [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 2;
}

我也現在想要實現使用這些方法(當我刪除這些方法,單元格邊框出現在模擬器灰線, 但不填充細胞)細胞:

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView;
- (NSInteger)numberOfRowsInSection:(NSInteger)section;
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;

如何簡單地使單元內部(在情節提要中)的對象出現在模擬器中工作? 如果您需要查看文檔大綱.m.h其他模擬器運行,只需請求它,我將發布。

PS底部的UIButton使用bottomLayoutGuide約束。

編輯:這是cellForRowAtIndexPath:方法的實現:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return grImageNameCell;
    return grBioCell;
}

這是這些IBOutlets的.h代碼:

@property (weak, nonatomic) IBOutlet UITableViewCell *grImageNameCell;
@property (weak, nonatomic) IBOutlet UITableViewCell *grBioCell;

原型細胞需要使用CellIdentifiers。 這就是代碼從Interface Builder知道要使用哪個單元的方式。

因此,您需要在這里做一些事情:

首先,為Interface Builder中的每個原型單元設置唯一的單元標識符

設置您的cellForRowAtIndexPath方法,如下所示:

- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath

{
   NSString* CellID1 = @"CellID1";
   NSString* CellID2 = @"CellID2";

   UITableViewCell* cell;

   if (indexPath.section == 0)
   {
      cell = [tableView dequeueReusableCellWithIdentifier:CellID1];
   }
   else
   {
      cell = [tableView dequeueReusableCellWithIdentifier:CellID2];
   }

   return cell;
}

注意:CellID1和CellID2是標識符。

使用它進行簡單的單元加載:

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
     return self.objectsArray.count;//where this is your array that you'll use to populate cells
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{        
    static NSString *CellIdentifier = @"identifier here";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

    return cell;
}

暫無
暫無

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

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