ios - 在 UITableView 中编程静态单元格

标签 ios iphone objective-c uitableview

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

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

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

enter image description here

这是我的 tableview 的图像及其在 Storyboard 中的属性:

enter image description here

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

到底是什么问题?

最佳答案

据我所知,静态内容仅适用于作为 Storyboard一部分的 UITableViewController。您的 View Controller 似乎是 UIViewController 的子类,因此它将无法从 Storyboard 中读取信息。

我不确定您是如何设法像您那样设置它的,但是可能可以将您的 SettingsViewController 重新定义为从 TableView Controller 而不是普通的继承 View Controller (执行此操作后您可能必须连接 tableView socket )。

要更改继承,请更改这行代码:

@interface SettingsViewController : UIViewController <   MFMailComposeViewControllerDelegate>

对此:

@interface SettingsViewController : UITableViewController <   MFMailComposeViewControllerDelegate>

如果没有,您可能需要将一个新的 TableView Controller 拖到 Storyboard 上并使用静态内容重新设置它。

关于ios - 在 UITableView 中编程静态单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20922441/

相关文章:

objective-c - 模仿 iOS 6 相机旋转

ios - 使用 MapboxStatic api 时,标记叠加层必须是 png、jpg 或 webp

ios - 无法将自动布局约束添加到UITableViewCell中的元素

ios - 为什么我在 Swift 中遇到 fatal error ?解包可选值时意外发现 nil

ios - SwiftUI 和 Combine - 在另一个更改时更新 View 模型中的变量

iphone - UITableView分隔符样式 "Single Line Etched"无法正常工作

iphone - iPad 2 上不显示图标

iphone - 如何在没有 Manifest.mbdx 的 iOS 5.0 beta 2 中解析 Manifest.mbdb 文件

objective-c - 将 NSDate 从日历转换为另一个日历

objective-c - 包含十六进制的 NSString 转换为等效的 ascii