【问题标题】:Programming Static Cells in UITableView在 UITableView 中编程静态单元格
【发布时间】:2014-01-05 02:57:04
【问题描述】:

我对 Xcode/应用程序开发有点陌生

我目前正在尝试在我的视图控制器中编写 4 个静态单元格。但是,当我运行我的应用程序时,tableview 没有显示。

这里是ios模拟器中发生的截图:

这里是我的 tableview 及其在情节提要中的属性的图像:

我的 SettingsViewController.h 文件:

#import <UIKit/UIKit.h>
#import <MessageUI/MessageUI.h>

@interface SettingsViewController : UIViewController <   MFMailComposeViewControllerDelegate>

@property (weak, nonatomic) IBOutlet UIBarButtonItem *sidebarButton;

@end

我的 SettingsViewController.m 文件:

#import "SettingsViewController.h"
#import "SWRevealViewController.h"

@interface SettingsViewController ()

@property (nonatomic, strong) NSArray *menuItems;

@end

@implementation SettingsViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
    // Custom initialization
}
return self;
}

- (void)viewDidLoad
{
[super viewDidLoad];
_sidebarButton.target = self.revealViewController;
_sidebarButton.action = @selector(revealToggle:);
_sidebarButton.tintColor = [UIColor colorWithWhite:0.1f alpha:0.7f];

// Add pan gesture to hide the sidebar
[self.view addGestureRecognizer:self.revealViewController.panGestureRecognizer];
// Do any additional setup after loading the view.
}



- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath  *)indexPath {
if(indexPath.row == 0 && indexPath.section == 0){
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://myawesomeapp.com/support"]];
} else if(indexPath.row == 0 && indexPath.section == 1){
         if ([MFMailComposeViewController canSendMail]) {
             MFMailComposeViewController *mailViewController = [[MFMailComposeViewController alloc] init];
             mailViewController.mailComposeDelegate = self;
             [mailViewController setSubject:@"[My Awesome App] Support request"];
             [mailViewController setToRecipients:[NSArray arrayWithObject:@"support@myawesomeapp.com"]];
             [self presentModalViewController:mailViewController animated:YES];
         }
          }

 }

  - (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error{
[self dismissModalViewControllerAnimated:YES];
 }

到底是什么问题?

【问题讨论】:

    标签: ios iphone objective-c uitableview


    【解决方案1】:

    据我所知,静态内容仅适用于作为情节提要的一部分的 UITableViewController。您的视图控制器似乎是 UIViewController 子类,因此它将无法从情节提要中读取信息。

    我不确定您是如何设法将其设置为像现在这样设置的,但可能只需将您的 SettingsViewController 重新定义为从表视图控制器继承而不是普通视图控制器视图控制器(您可能需要在完成此操作后连接tableView 插座)。

    要改变继承,改变这行代码:

    @interface SettingsViewController : UIViewController <   MFMailComposeViewControllerDelegate>
    

    到这里:

    @interface SettingsViewController : UITableViewController <   MFMailComposeViewControllerDelegate>
    

    如果没有,您可能需要将新的表格视图控制器拖到情节提要上,并使用静态内容再次设置它。

    【讨论】:

      【解决方案2】:

      您应该通过将&lt;UITableViewDelegate&gt; 添加到您的 .h 文件来采用 UITableViewDelegate 协议。

      之后,您需要将表格视图连接到相关的 .h 或 .m 文件,并使其成为相关表格的委托。

      随便看看this教程..

      【讨论】:

      • 我只需要在我的 .h 文件中添加一个 UITableViewDelegate 吗?然后我需要将委托连接到我的视图控制器?我不需要添加 UITableViewDataSource?
      • 我尝试在我的 SettingsViewController.h 中实现 UITableViewDelegate 协议,并且我还将我的 tableview 的委托出口连接到情节提要中的 SettingsViewController。什么也没发生。
      【解决方案3】:

      在故事板尺寸检查器中,尝试使用足够大的值设置高度、宽度和原点。如果这使它可见,则在同一个检查器中使用自动拉伸属性(抱歉,不记得确切的名称)。

      【讨论】:

        猜你喜欢
        • 2012-06-26
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-10-21
        • 1970-01-01
        相关资源
        最近更新 更多