TableView项目未显示

时间:2013-02-19 01:54:06

标签: ios objective-c cocoa-touch uitableview

我对XCode了解不多。好吧,我知道对XCode没什么好处的。但是我遇到了TableView的问题。

我关注This Tutorial但是当我尝试自己制作时,除了TableView项目外,一切都很完美。我试过的所有涉及表视图的教程都给了我同样的问题。没有显示任何项目:(我将留下完整项目的下载链接,因为我不确定你需要什么代码来帮助我。

Download Link (MediaFire)

请帮助!我的脑袋即将爆炸......

这是我尝试运行应用程序时遇到的错误。

//
//  main.m
//  Demo TWo
//
//  Created by Alexander Pina on 2/18/13.
//  Copyright (c) 2013 Alexander Pina. All rights reserved.
//

#import <UIKit/UIKit.h>

#import "AppDelegate.h"

int main(int argc, char *argv[])
{
    @autoreleasepool {
        return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
    }
}

在@autoreleasepoo {...它告诉我,“线程1:信号SIGABRT

3 个答案:

答案 0 :(得分:0)

添加代表&amp;数据源。我认为你忘了添加代理和数据源,这就是为什么它没有显示表。将以下行添加到viewDidLoad()。如下面的代码

self.myTableView.dataSource = self;
  self.myTableView.delegate = self;

答案 1 :(得分:0)

我看了你的项目。我认为,您的问题是由Xcode中的错误引起的。这可能发生在连接xib或Storyboard文件中,并且在更改了xib文件的文件检查器中的某些内容后,我遇到了很多问题。

您的Tab2_TableViewController类代码未被使用,即使您在故事板中将UITableViewController的自定义类名设置为Tab2_TableViewController。我通过在您的Tab2_TableViewController子类的viewDidLoad中放置一个断点并看到该方法从未被调用来测试它。它应该可以工作,但是在Xcode中搞砸了一些东西,所以它不起作用。

我通过这样做解决了这个问题:

  • 将Tab2_TableViewController.h和.m文件复制到另一个文件夹
  • 从Xcode项目中删除Tab2_TableViewController.h和.m
  • 将Tab2_TableViewController.h和.m从另一个文件夹复制回Xcode项目。

这就是我所做的一切,它解决了问题,表视图单元格现在被加载到视图中。


实际上我找到了解决问题的更好方法。在Xcode项目导航器中,选择项目文件。选择目标DemoTWo-&gt; Build Phases-&gt; Compile Sources。点击小“+”按钮并添加Tab2_TableViewController.m。通常,当您添加文件时,它们会自动添加到此列表中,但无论出于何种原因,该文件都未添加到您的案例中。

enter image description here

答案 2 :(得分:-1)

试试这个,

- &gt;只需在xcode中创建基于View Application的单个示例项目

ViewController.h

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController<UITableViewDataSource,UITableViewDelegate>

{
IBOutlet UITableView *TableView;
NSArray *arrItems;
}
@end

viewcontroller.m

     #import "ViewController.h"
     @interface ViewController ()

     @end

     @implementation ViewController

      - (void)viewDidLoad
     {
         [super viewDidLoad];
         arrItems =[[NSArray alloc]initWithObjects:@"row1",@"row2",@"row3",@"row4",@"row5",@"row6",@"row7", nil];
        TableView.dataSource =self;
         TableView.delegate =self;
// Do any additional setup after loading the view, typically from a nib.
     }
        #pragma mark -
        #pragma mark Table view data source

      - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
         // Return the number of sections.
         return 1;
         }


      - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
         // Return the number of rows in the section.
      return [arrItems count];
              }


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

        static NSString *CellIdentifier = @"Cell";

       UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
         if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];

    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    [cell.textLabel setFont:[UIFont boldSystemFontOfSize:16]];
    [cell.textLabel setTextColor:[UIColor colorWithRed:0 green:0.5 blue:0 alpha:1]];
          }

    cell.textLabel.text = [arrItems objectAtIndex:indexPath.row];
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    return cell;
         }



     #pragma mark -
     #pragma mark Table view delegate

         - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {


         }
相关问题