我对 Xcode/应用程序开发有点陌生
我目前正在尝试在我的 View Controller 中编写 4 个静态单元格。但是,当我去运行我的应用程序时,tableview 没有显示。
这里是 ios 模拟器中发生的截图:
这是我的 tableview 的图像及其在 Storyboard 中的属性:
我的 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/