簡體   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