繁体   English   中英

在UITableView中编程静态单元格

[英]Programming Static Cells in UITableView

我是Xcode / app开发的新手

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

以下是ios模拟器中发生的情况的屏幕截图:

在此处输入图片说明

这是我的表视图的图像及其在故事板上的属性:

在此处输入图片说明

我的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];
 }

到底是什么问题?

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

我不知道你怎么已经成功地得到它建立像你有,但它可能只是为了重新定义SettingsViewController从表视图控制器,而不是一个简单的视图控制器继承(您可能需要连接tableView执行此操作后,请关闭电源。

要更改继承,请更改以下代码行:

@interface SettingsViewController : UIViewController <   MFMailComposeViewControllerDelegate>

对此:

@interface SettingsViewController : UITableViewController <   MFMailComposeViewControllerDelegate>

如果不是,则可能必须将新的表格视图控制器拖到情节提要上,并使用静态内容再次进行设置。

您应该通过将<UITableViewDelegate>添加到.h文件中来采用UITableViewDelegate协议。

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

无论如何,请简要阅读教程。

在情节提要板大小检查器中,尝试使用足够大的值设置高度,宽度和原点。 如果可以看到,请在同一检查器中使用自动拉伸属性(对不起,忘记了确切的名称)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM