【问题标题】:UIDatePicker Scheduler ErrorUIDatePicker 调度程序错误
【发布时间】:2013-04-11 15:41:16
【问题描述】:

我已经按照这个教程 http://ios.biomsoft.com/2011/08/27/iphone-programming-tutorial---local-notifications/ 我能够运行该应用程序,但是为了运行该应用程序,我在我的 appdelegate.m 中删除了以下代码

您可以在上图中看到错误。

为什么我会收到错误以及如何修复错误?

这是我的代码。

.h

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController <UITableViewDelegate,UITableViewDataSource> {
IBOutlet UITableView *tableview;
IBOutlet UIDatePicker *datePicker;
IBOutlet UITextField *eventText;
}

@property (nonatomic, retain) IBOutlet UITableView *tableview;
@property (nonatomic, retain) IBOutlet UIDatePicker *datePicker;
@property (nonatomic, retain) IBOutlet UITextField *eventText;

- (IBAction) scheduleAlarm:(id) sender;

@end

.m

@implementation ViewController

@synthesize datePicker,tableview, eventText;

- (IBAction) scheduleAlarm:(id) sender {

[eventText resignFirstResponder];

NSCalendar *calendar = [NSCalendar autoupdatingCurrentCalendar];

// Get the current date
NSDate *pickerDate = [self.datePicker date];

// Break the date up into components
NSDateComponents *dateComponents = [calendar components:( NSYearCalendarUnit | 
NSMonthCalendarUnit |  NSDayCalendarUnit )

fromDate:pickerDate];
NSDateComponents *timeComponents = [calendar components:( NSHourCalendarUnit | 
NSMinuteCalendarUnit | NSSecondCalendarUnit )

fromDate:pickerDate];
// Set up the fire time
NSDateComponents *dateComps = [[NSDateComponents alloc] init];
[dateComps setDay:[dateComponents day]];
[dateComps setMonth:[dateComponents month]];
[dateComps setYear:[dateComponents year]];
[dateComps setHour:[timeComponents hour]];
// Notification will fire in one minute
[dateComps setMinute:[timeComponents minute]];
[dateComps setSecond:[timeComponents second]];
NSDate *itemDate = [calendar dateFromComponents:dateComps];

UILocalNotification *localNotif = [[UILocalNotification alloc] init];
if (localNotif == nil)
    return;
localNotif.fireDate = itemDate;
localNotif.timeZone = [NSTimeZone defaultTimeZone];

// Notification details
localNotif.alertBody = [eventText text];
// Set the action button
localNotif.alertAction = @"View";

localNotif.soundName = UILocalNotificationDefaultSoundName;
localNotif.applicationIconBadgeNumber = 1;

// Specify custom data for the notification
NSDictionary *infoDict = [NSDictionary dictionaryWithObject:@"someValue"  
forKey:@"someKey"];
localNotif.userInfo = infoDict;

// Schedule the notification
[[UIApplication sharedApplication] scheduleLocalNotification:localNotif];

[self.tableview reloadData];

}

- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}

- (void)viewDidUnload {
datePicker = nil;
tableview = nil;
eventText = nil;
}

- (void)viewDidLoad{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
// We only have one section
return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
// Return the number of notifications
return [[[UIApplication sharedApplication] scheduledLocalNotifications] count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath   
*)indexPath {

static NSString *CellIdentifier = @"Cell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle  
reuseIdentifier:CellIdentifier];
}

// Get list of local notifications
NSArray *notificationArray = [[UIApplication sharedApplication]    
scheduledLocalNotifications];
UILocalNotification *notif = [notificationArray objectAtIndex:indexPath.row];

// Display notification info
[cell.textLabel setText:notif.alertBody];
[cell.detailTextLabel setText:[notif.fireDate description]];

return cell;
}
@end

【问题讨论】:

    标签: iphone ipad xcode4.5 uidatepicker appdelegate


    【解决方案1】:

    您必须创建viewControllerfirst 的实例:

    ViewController *viewController = [[ViewController alloc] init];
    // set the frame, do other stuff..
    [_window addSubview:viewController.view];
    

    【讨论】:

      【解决方案2】:

      请先检查您的 AppDelegate 代码

      - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
      {
          self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
          // Override point for customization after application launch.
          self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
      
         /******
             YOUR CODE HERE
      
         ******/
      
          self.window.rootViewController = self.viewController;
          [self.window makeKeyAndVisible];
      
      
          return YES;
      }
      

      【讨论】:

      • 是的,抱歉,意外返回。 self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];必须将 [[viewcontroller alloc] 更改为 [[ViewController alloc]。然后我收到一条错误消息:在'AppDelegate *'类型的对象上找不到属性'viewController' 我在self.window.rootViewController = self.viewController;这一行也收到了同样的错误
      【解决方案3】:

      好吧,在玩了一些之后。我能够让应用程序运行,而无需更改应用程序委托。

      不知道为什么他在教程中声明要这样做。

      感谢您的帮助。

      【讨论】:

      • 我没有将 BOOL 添加到应用委托中。
      猜你喜欢
      • 1970-01-01
      • 2015-03-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-07-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多