Memo | |
時たま、こんなサンプルを見ますが、これってとってもトラブルの原因になってしまいます。
// - (void) viewDidLoad { // Interface Builder で Navigation Controller を別定義してあって、 // File's Owner の View Controller の view にその view を突っ込もうとする [self.view addSubView:navControl.view]; }
たとえばこんな良くないことが・・・・
これで1年半くらい悩んでました・・・orz
これ、結局どうすればいいかわからんっていわれてたので、僕はこうしたという話を。
NavigationController 自体、またはその継承クラスを presentModalViewController で表示させるのがひとまず正しそうで、Interface Builderを使わずに以下のように継承クラスを作成。
// SettingViewController.h @interface SettingViewController : UINavigationController { @private MainSettingPageViewController* mainPage; } - (id) initWithSettingRootViewController; - (void) dismiss; @end // SettingViewController.m @implementation SettingViewController @synthesize mainPage; - (id) initWithSettingRootViewController { // Setup MainPage (RootView) return [self initWithRootViewController:[[MainSettingPageViewController alloc] initWithOwner:self]]; } - (void) dismiss { [self dismissModalViewControllerAnimated:YES]; } @end
そしてあとはこいつをインスタンス化してpresentModalViewControllerで表示。
[self presentModalViewController:[SettingViewTestAppDelegate appDelegate].settingController animated:YES];
「そういえばUINavigationControllerもUIViewControllerの派生クラスだよなー」と思って試してみたらうまくいきました。
Memo | |
lastImage に UIImage が、lastLocation に CLLocation が入っています。
CGImageSourceRef img = CGImageSourceCreateWithData((CFDataRef)UIImageJPEGRepresentation(lastImage, 0.7), NULL); NSMutableDictionary* exifDict = [[[NSMutableDictionary alloc] init] autorelease]; NSMutableDictionary* locDict = [[[NSMutableDictionary alloc] init] autorelease]; NSDateFormatter* dateFormatter = [[[NSDateFormatter alloc] init] autorelease]; [dateFormatter setDateFormat:@"yyyy:MM:dd HH:mm:ss"]; NSString* datetime = [dateFormatter stringFromDate:lastLocation.timestamp]; [exifDict setObject:datetime forKey:(NSString*)kCGImagePropertyExifDateTimeOriginal]; [exifDict setObject:datetime forKey:(NSString*)kCGImagePropertyExifDateTimeDigitized]; [locDict setObject:lastLocation.timestamp forKey:(NSString*)kCGImagePropertyGPSTimeStamp]; if (lastLocation.coordinate.latitude <0.0){ [locDict setObject:@"S" forKey:(NSString*)kCGImagePropertyGPSLatitudeRef]; }else{ [locDict setObject:@"N" forKey:(NSString*)kCGImagePropertyGPSLatitudeRef]; } [locDict setObject:[NSNumber numberWithFloat:lastLocation.coordinate.latitude] forKey:(NSString*)kCGImagePropertyGPSLatitude]; if (lastLocation.coordinate.longitude <0.0){ [locDict setObject:@"W" forKey:(NSString*)kCGImagePropertyGPSLongitudeRef]; }else{ [locDict setObject:@"E" forKey:(NSString*)kCGImagePropertyGPSLongitudeRef]; } [locDict setObject:[NSNumber numberWithFloat:lastLocation.coordinate.longitude] forKey:(NSString*)kCGImagePropertyGPSLongitude]; NSMutableData* imageData = [[[NSMutableData alloc] init] autorelease]; CGImageDestinationRef dest = CGImageDestinationCreateWithData((CFMutableDataRef)imageData, CGImageSourceGetType(img), 1, NULL); CGImageDestinationAddImageFromSource(dest, img, 0, (CFDictionaryRef)[NSDictionary dictionaryWithObjectsAndKeys: locDict, (NSString*)kCGImagePropertyGPSDictionary, exifDict, (NSString*)kCGImagePropertyExifDictionary, nil]); CGImageDestinationFinalize(dest); CFRelease(img); CFRelease(dest);
ちゃんとした記事にするまでのメモ。
MonoTouch | |
UITableView はあまりの面倒くささに毎回やる気なくなるし、着手しても発狂するのでテンプレ化。MonoTouch で UITableView を使うときのサンプルとしてもどうぞ。
ちなみに、このクラスには Interface Builder で UITableView おいて、コントローラに tableView という名前で結合してあります。
ここまでかいておけばあとは overrde[space] で MonoDevelop が実装できるメソッドを教えてくれるのでちょっと気が楽。
MonoTouch | |
- (void) initKeyboardEvent { [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil]; } // キーボードオープンイベント - (void) keyboardWillShow:(NSNotification*)notif { // キーボードの大きさを取得 NSDictionary* info = [notif userInfo]; NSValue* aValue = [info objectForKey:UIKeyboardBoundsUserInfoKey]; CGRect keyboardRect = [aValue CGRectValue]; }
private void KeyboardInit() { m_keybordWillShowNotificationObj = NSNotificationCenter.DefaultCenter.AddObserver("UIKeyboardWillShowNotification", KeyboardOpen); } private void KeyboardWillOpen(NSNotification notification) { NSDictionary dict = notification.UserInfo; NSValue val = dict.ObjectForKey(UIKeyboard.BoundsUserInfoKey); RectangleF rect = val.RectangleFValue; }
splitViewControllerはmodal表示できないとか、検索してもなかなか出てこなかったんですよね...