3つのタブがあるUITabBarアプリケーションがあります。最初のタブには、ユーザーが日付を選択できるようにするモーダルUIViewControllerを表示するUIButtonを備えたUIViewControllerがあります。ユーザーが選択した日付を選択したときに、UIButtonのラベルを更新するのに問題があります。
私のメインビューコントローラー.h/.m
#import <UIKit/UIKit.h>
@interface SearchViewController : UIViewController {
IBOutlet UIButton *butFromDate;
}
@property (nonatomic, retain) UIButton *butFromDate;
- (IBAction)pickDate:(id)sender;
@end
////////////////////////////////////////////
#import "SearchViewController.h"
#import "SearchDatePickerViewController.h"
@implementation SearchViewController
@synthesize butFromDate;
- (IBAction)pickDate:(id)sender{
SearchDatePickerViewController *sampleView = [[[SearchDatePickerViewController alloc] init] autorelease];
[sampleView setModalTransitionStyle:UIModalTransitionStylePartialCurl];
[self presentModalViewController:sampleView animated:YES];
}
- (void)dealloc {
[butFromDate release];
[super dealloc];
}
@end
次に、私のモーダルウィンドウ(UIPickerと、ユーザーの選択をキャンセルまたは保存するためのUIBarButtonがいくつかあります).h/.mは次のようになります。
#import <UIKit/UIKit.h>
@interface SearchDatePickerViewController : UIViewController <UIPickerViewDelegate, UIPickerViewDataSource> {
NSMutableArray *dates;
IBOutlet UIPickerView *picker;
}
@property (nonatomic, retain) NSMutableArray *dates;
@property (nonatomic, retain) UIPickerView *picker;
- (IBAction)cancelDatePick:(id)sender;
- (IBAction)pickDate:(id)sender;
@end
////////////////////////////////////////////
#import "SearchDatePickerViewController.h"
#import "SearchViewController.h"
#import "AppDelegate.h"
#import "Search.h"
@implementation SearchDatePickerViewController
@synthesize dates, picker;
- (IBAction)cancelDatePick:(id)sender{
[self dismissModalViewControllerAnimated:YES];
}
- (IBAction)pickDate:(id)sender{
HolidayCottagesAppDelegate *appDelegate = (HolidayCottagesAppDelegate *)[[UIApplication sharedApplication] delegate];
SearchViewController *searchView = [SearchViewController alloc];
appDelegate.currentSearch.fromDate = [dates objectAtIndex:[picker selectedRowInComponent:0]];
[searchView.butFromDate setTitle:@"HELLO-TEST" forState:UIControlStateNormal];
[self dismissModalViewControllerAnimated:YES];
}
- (void)viewDidLoad {
[super viewDidLoad];
NSDate* curDate = [NSDate date];
NSCalendar* calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSDateComponents* comps = [calendar components:NSYearCalendarUnit|NSMonthCalendarUnit|NSWeekCalendarUnit|NSWeekdayCalendarUnit fromDate:curDate];
NSTimeZone* gmt = [NSTimeZone timeZoneWithAbbreviation:@"GMT"];
dates = [[NSMutableArray alloc] init];
[comps setTimeZone:gmt];
[comps setWeekday:7];
int startCount = comps.week + 1;
int endCount = (((52 - startCount) + 52) + startCount);
for (startCount; startCount <= endCount; startCount++){
NSDate *tDate = [calendar dateFromComponents:comps];
[dates addObject:tDate];
[comps setWeek:startCount];
}
}
// OTHER SHIZZLE HERE BUT NOT REALLY NEEDED TO DISPLAY...
したがって、[保存]ボタンをクリックすると、-(void)pickDate:all okが実行され、モーダルビューが閉じられますが、SearchViewControllerのUIButtonラベルが「HELLO-TEST」に更新されません。私はここで簡単な何かが欠けていると確信しています...
私を助けてください!!
ありがとう :)