Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Diary input field and text view UI are refined.

  • Loading branch information...
commit aee75fd363c9a7e9f7fb08ebb16418d1d054489a 1 parent 9dbbbe0
Kishikawa Katsumi authored
View
9 Classes/DiaryViewController.h
@@ -1,14 +1,13 @@
#import <UIKit/UIKit.h>
#import "Diary.h"
-@interface DiaryViewController : UITableViewController <UITableViewDataSource , UITextFieldDelegate, UITextViewDelegate,
-UINavigationControllerDelegate, UIImagePickerControllerDelegate> {
+@interface DiaryViewController : UIViewController
+<UITextFieldDelegate, UITextViewDelegate, UINavigationControllerDelegate, UIImagePickerControllerDelegate> {
UITextField *titleField;
UITextView *bodyView;
UIButton *draftButton;
UIButton *submitButton;
- UITableView *diaryView;
UISegmentedControl *toolButtons;
NSString *editURI;
@@ -17,7 +16,7 @@ UINavigationControllerDelegate, UIImagePickerControllerDelegate> {
NSString *titleTextForEdit;
NSString *diaryTextForEdit;
- Diary *edittingDiary;
+ Diary *editingDiary;
NSString *dataFilePath;
BOOL shoudSaveOnExit;
@@ -31,7 +30,7 @@ UINavigationControllerDelegate, UIImagePickerControllerDelegate> {
@property (nonatomic) BOOL editDraft;
@property (nonatomic, retain) NSString *titleTextForEdit;
@property (nonatomic, retain) NSString *diaryTextForEdit;
-@property (nonatomic, retain) Diary *edittingDiary;
+@property (nonatomic, retain) Diary *editingDiary;
@property (nonatomic, retain) NSString *dataFilePath;
- (void)done:(id)sender;
View
205 Classes/DiaryViewController.m
@@ -21,13 +21,10 @@ @implementation DiaryViewController
@synthesize editDraft;
@synthesize titleTextForEdit;
@synthesize diaryTextForEdit;
-@synthesize edittingDiary;
+@synthesize editingDiary;
@synthesize dataFilePath;
- (void)dealloc {
- diaryView.delegate = nil;
- diaryView.dataSource = nil;
- [diaryView release];
[toolButtons release];
[titleField release];
[bodyView release];
@@ -35,7 +32,7 @@ - (void)dealloc {
[submitButton release];
[dataFilePath release];
[editURI release];
- [edittingDiary release];
+ [editingDiary release];
[titleTextForEdit release];
[diaryTextForEdit release];
[super dealloc];
@@ -149,6 +146,7 @@ - (void)dealloc {
#pragma mark Temp file access Methods
- (void)loadTemporaryDiary {
+ LOG_CURRENT_METHOD;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentDirectory = [paths objectAtIndex:0];
NSString *path = [documentDirectory stringByAppendingPathComponent:@"Diary.temp"];
@@ -159,32 +157,36 @@ - (void)loadTemporaryDiary {
NSMutableData *theData = [NSMutableData dataWithContentsOfFile:path];
NSKeyedUnarchiver *decoder = [[NSKeyedUnarchiver alloc] initForReadingWithData:theData];
- self.edittingDiary = [decoder decodeObjectForKey:@"diary"];
+ self.editingDiary = [decoder decodeObjectForKey:@"diary"];
[decoder finishDecoding];
[decoder release];
} else {
- self.edittingDiary = [[Diary alloc] init];
+ self.editingDiary = [[Diary alloc] init];
}
+ LOG(@"%@", editingDiary);
}
- (void)saveTemporaryDiary {
+ LOG_CURRENT_METHOD;
if ([titleTextForEdit length] != 0 || [diaryTextForEdit length] != 0) {
//下書き or 過去の日記の修正の場合は保存しない
return;
}
- edittingDiary.titleText = titleField.text;
- edittingDiary.diaryText = bodyView.text;
+ editingDiary.titleText = titleField.text;
+ editingDiary.diaryText = bodyView.text;
NSMutableData *theData = [NSMutableData data];
NSKeyedArchiver *encoder = [[NSKeyedArchiver alloc] initForWritingWithMutableData:theData];
- [encoder encodeObject:edittingDiary forKey:@"diary"];
+ [encoder encodeObject:editingDiary forKey:@"diary"];
[encoder finishEncoding];
[theData writeToFile:dataFilePath atomically:YES];
[encoder release];
+
+ LOG(@"%@", editingDiary);
}
- (void)deleteTemporaryDiary {
@@ -202,8 +204,8 @@ - (void)deleteTemporaryDiary {
#pragma mark GUI Methods
- (BOOL)orientationIsPortrait {
- UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
- if (orientation == UIDeviceOrientationIsPortrait(orientation)) {
+ UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
+ if (UIInterfaceOrientationIsPortrait(orientation)) {
return YES;
} else {
return NO;
@@ -216,7 +218,7 @@ - (void)enableToolButtons:(BOOL)isEnable {
}
}
-- (void) beginEditting {
+- (void)beginEditting {
UIBarButtonItem* doneButton = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone
target:self action:@selector(done:)] autorelease];
[[self navigationItem] setRightBarButtonItem:doneButton animated:YES];
@@ -227,14 +229,14 @@ - (void) beginEditting {
}
}
-- (void) finishEditting {
+- (void)finishEditting {
self.navigationItem.rightBarButtonItem = nil;
[[self navigationItem] setHidesBackButton:NO animated:YES];
[self enableToolButtons:NO];
[self saveTemporaryDiary];
}
-- (void) enableButtons {
+- (void)enableButtons {
if ([[titleField text] length] != 0 && [bodyView hasText]) {
[submitButton setEnabled:YES];
[draftButton setEnabled:YES];
@@ -246,75 +248,25 @@ - (void) enableButtons {
- (void)moveUpButtons {
if ([self orientationIsPortrait]) {
- [bodyView setFrame:CGRectMake(0.0, 0.0, 320.0, 179.0)];
+ if (IPHONE_OS_VERSION < 3.0) {
+ [bodyView setFrame:CGRectMake(0.0f, 40.0f, 320.0f, 160.0f)];
+ } else {
+ [bodyView setFrame:CGRectMake(0.0f, 40.0f, 320.0f, 160.0f)];
+ }
} else {
- [bodyView setFrame:CGRectMake(0.0, 0.0, 480.0, 120.0)];
+ if (IPHONE_OS_VERSION < 3.0) {
+ [bodyView setFrame:CGRectMake(0.0, 40.0f, 480.0, 108.0)];
+ } else {
+ [bodyView setFrame:CGRectMake(0.0, 40.0f, 480.0, 116.0)];
+ }
}
}
- (void)moveDownButtons {
if ([self orientationIsPortrait]) {
- [bodyView setFrame:CGRectMake(0.0, 0.0, 320.0, 328.0)];
+ [bodyView setFrame:CGRectMake(0.0f, 40.0f, 320.0f, 332.0f)];
} else {
- [bodyView setFrame:CGRectMake(0.0, 0.0, 480.0, 212.0)];
- }
-}
-
-#pragma mark <UITableViewDataSource> Methods
-
-- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
- if (indexPath.row == 0) {
- return 40.0f;
- } else if (indexPath.row == 1) {
- return 386.0f;
- } else {
- return 44.0f;
- }
-}
-
-- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
- return 1;
-}
-
-- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
- return 2;
-}
-
-- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
- if (indexPath.row == 0) {
- UITableViewCell *cell = [diaryView dequeueReusableCellWithIdentifier:@"TitleCell"];
- if (cell == nil) {
- cell = [[[UITableViewCell alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 320.0f, 40.0f) reuseIdentifier:@"TitleCell"] autorelease];
- cell.accessoryType = UITableViewCellAccessoryNone;
- cell.selectionStyle = UITableViewCellSelectionStyleNone;
- [cell addSubview:titleField];
- }
-
- if (titleTextForEdit) {
- [titleField setText:titleTextForEdit];
- } else {
- [titleField setText:edittingDiary.titleText];
- }
- return cell;
- } else {
- UITableViewCell *cell = [diaryView dequeueReusableCellWithIdentifier:@"DiaryCell"];
- if (cell == nil) {
- cell = [[[UITableViewCell alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 320.0f, 386.0f) reuseIdentifier:@"DiaryCell"] autorelease];
- [cell addSubview:bodyView];
- [cell addSubview:draftButton];
- [cell addSubview:submitButton];
- }
-
- if (editEntry) {
- [draftButton removeFromSuperview];
- }
-
- if (diaryTextForEdit) {
- [bodyView setText:diaryTextForEdit];
- } else {
- [bodyView setText:edittingDiary.diaryText];
- }
- return cell;
+ [bodyView setFrame:CGRectMake(0.0, 40.0f, 480.0, 212.0)];
}
}
@@ -358,13 +310,6 @@ - (BOOL)textFieldShouldEndEditing:(UITextField *)textField {
#pragma mark <UITextViewDelegate> Methods
-//- (void)textViewDidBeginEditing:(UITextView *)textView {
-// isEdittingDiaryText = YES;
-// [self enableButtons];
-// [self moveUpButtons];
-// [self beginEditting];
-//}
-
- (void)textViewDidChange:(UITextView *)textView {
if ([bodyView.text length] != 0 && [titleField.text length] != 0) {
[submitButton setEnabled:YES];
@@ -586,35 +531,51 @@ - (void)submitDraft:(id)sender {
#pragma mark <UIViewController> Methods
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
- if (fromInterfaceOrientation == UIDeviceOrientationIsPortrait(fromInterfaceOrientation)) {
- [submitButton setFrame:CGRectMake(380.0, 220.0, 80.0, 30.0)];
- [draftButton setFrame:CGRectMake(292.0, 220.0, 80.0, 30.0)];
- if (isEdittingDiaryText) {
- [bodyView setFrame:CGRectMake(0.0, 0.0, 480.0, 120.0)];
- } else {
- [bodyView setFrame:CGRectMake(0.0, 0.0, 480.0, 212.0)];
- }
- [self.navigationController setNavigationBarHidden:YES animated:YES];
- } else {
- [submitButton setFrame:CGRectMake(220.0, 336.0, 80.0, 30.0)];
- [draftButton setFrame:CGRectMake(132.0, 336.0, 80.0, 30.0)];
- if (isEdittingDiaryText || [titleField isEditing]) {
- [bodyView setFrame:CGRectMake(0.0, 0.0, 320.0, 179.0)];
- } else {
- [bodyView setFrame:CGRectMake(0.0, 0.0, 320.0, 328.0)];
- }
+ LOG_CURRENT_METHOD;
+ if ([self orientationIsPortrait]) {
+ [submitButton setFrame:CGRectMake(220.0, 376.0, 80.0, 30.0)];
+ [draftButton setFrame:CGRectMake(132.0, 376.0, 80.0, 30.0)];
+ if (IPHONE_OS_VERSION < 3.0) {
+ if (isEdittingDiaryText || [titleField isEditing]) {
+ [bodyView setFrame:CGRectMake(0.0, 40.0f, 320.0, 164.0f)];
+ } else {
+ [bodyView setFrame:CGRectMake(0.0, 40.0f, 320.0, 332.0)];
+ }
+ } else {
+ if (isEdittingDiaryText || [titleField isEditing]) {
+ [bodyView setFrame:CGRectMake(0.0, 40.0f, 320.0, 204.0f)];
+ } else {
+ [bodyView setFrame:CGRectMake(0.0, 40.0f, 320.0, 376.0)];
+ }
+ }
[self.navigationController setNavigationBarHidden:NO animated:YES];
+ } else {
+ [submitButton setFrame:CGRectMake(380.0, 264.0, 80.0, 30.0)];
+ [draftButton setFrame:CGRectMake(292.0, 264.0, 80.0, 30.0)];
+ if (IPHONE_OS_VERSION < 3.0) {
+ if (isEdittingDiaryText) {
+ [bodyView setFrame:CGRectMake(0.0, 40.0f, 480.0, 108.0)];
+ } else {
+ [bodyView setFrame:CGRectMake(0.0, 40.0f, 480.0, 216.0)];
+ }
+ } else {
+ if (isEdittingDiaryText) {
+ [bodyView setFrame:CGRectMake(0.0, 40.0f, 480.0, 84.0)];
+ } else {
+ [bodyView setFrame:CGRectMake(0.0, 40.0f, 480.0, 184.0)];
+ }
+ }
+ [self.navigationController setNavigationBarHidden:YES animated:YES];
}
}
- (void)loadView {
- diaryView = [[UITableView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 320.0f, 460.0f)];
- diaryView.scrollEnabled = NO;
- [diaryView setDelegate:self];
- [diaryView setDataSource:self];
- [self setView:diaryView];
+ UIView *contentView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 320.0f, 460.0f)];
+ contentView.backgroundColor = [UIColor whiteColor];
+ [self setView:contentView];
+ [contentView release];
- titleField = [[UITextField alloc] initWithFrame:CGRectMake(20.0f, 4.0f, 300.0f, 32.0f)];
+ titleField = [[UITextField alloc] initWithFrame:CGRectMake(10.0f, 4.0f, 310.0f, 33.0f)];
[titleField setDelegate:self];
[titleField setAdjustsFontSizeToFitWidth:NO];
[titleField setBorderStyle:UITextBorderStyleNone];
@@ -629,28 +590,34 @@ - (void)loadView {
[titleField setPlaceholder:NSLocalizedString(@"Title", nil)];
[titleField setKeyboardType:UIKeyboardTypeDefault];
[titleField setAutoresizingMask:UIViewAutoresizingFlexibleWidth];
+ [contentView addSubview:titleField];
- bodyView = [[UITextView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 320.0f, 328.0f)];
+ bodyView = [[UITextView alloc] initWithFrame:CGRectMake(0.0f, 40.0f, 320.0f, 376.0f)];
[bodyView setDelegate:self];
[bodyView setAutocapitalizationType:UITextAutocapitalizationTypeNone];
[bodyView setAutocorrectionType:UITextAutocorrectionTypeNo];
- [bodyView setReturnKeyType:UIReturnKeyDone];
+ [bodyView setReturnKeyType:UIReturnKeyDefault];
[bodyView setKeyboardType:UIKeyboardTypeDefault];
[bodyView setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight];
+ bodyView.font = [UIFont systemFontOfSize:14.0f];
+ [contentView addSubview:bodyView];
draftButton = [[UIButton buttonWithType:UIButtonTypeRoundedRect] retain];
[draftButton setTitle:NSLocalizedString(@"DraftButton", nil) forState:UIControlStateNormal];
- draftButton.frame = CGRectMake(132.0f, 336.0f, 80.0f, 30.0f);
+ draftButton.frame = CGRectMake(132.0f, 376.0f, 80.0f, 30.0f);
+ [contentView addSubview:draftButton];
submitButton = [[UIButton buttonWithType:UIButtonTypeRoundedRect] retain];
[submitButton setTitle:NSLocalizedString(@"SubmitButton", nil) forState:UIControlStateNormal];
- submitButton.frame = CGRectMake(220.0f, 336.0f, 80.0f, 30.0f);
+ submitButton.frame = CGRectMake(220.0f, 376.0f, 80.0f, 30.0f);
+ [contentView addSubview:submitButton];
[draftButton addTarget:self action:@selector(submitDraft:) forControlEvents:UIControlEventTouchUpInside];
[submitButton addTarget:self action:@selector(submit:) forControlEvents:UIControlEventTouchUpInside];
}
- (void)viewDidLoad {
+ LOG_CURRENT_METHOD;
[super viewDidLoad];
self.view.autoresizesSubviews = YES;
self.view.autoresizingMask = UIViewAutoresizingFlexibleWidth;
@@ -674,13 +641,28 @@ - (void)viewDidLoad {
}
- (void)viewWillAppear:(BOOL)animated {
+ LOG_CURRENT_METHOD;
[super viewWillAppear:animated];
[self loadTemporaryDiary];
+ if (titleTextForEdit) {
+ [titleField setText:titleTextForEdit];
+ } else {
+ [titleField setText:editingDiary.titleText];
+ }
+ if (editEntry) {
+ [draftButton removeFromSuperview];
+ }
+ if (diaryTextForEdit) {
+ [bodyView setText:diaryTextForEdit];
+ } else {
+ [bodyView setText:editingDiary.diaryText];
+ }
shoudSaveOnExit = YES;
[self enableToolButtons:NO];
}
- (void)viewDidAppear:(BOOL)animated {
+ LOG_CURRENT_METHOD;
[super viewDidAppear:animated];
[self enableButtons];
@@ -688,6 +670,7 @@ - (void)viewDidAppear:(BOOL)animated {
}
- (void)viewWillDisappear:(BOOL)animated {
+ LOG_CURRENT_METHOD;
if (shoudSaveOnExit) {
[self saveTemporaryDiary];
}
View
2  Classes/RootViewController.m
@@ -109,7 +109,7 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if ([self hasDoneSettings] && indexPath.section == 0 && indexPath.row == 0) {
- DiaryViewController *controller = [[DiaryViewController alloc] initWithStyle:UITableViewStylePlain];
+ DiaryViewController *controller = [[DiaryViewController alloc] init];
[[self navigationController] pushViewController:controller animated:YES];
[controller release];
} else if ([self hasDoneSettings] && indexPath.section == 0 && indexPath.row == 1) {
View
26 HatenaTouch.xcodeproj/project.pbxproj
@@ -669,10 +669,12 @@
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
HEADER_SEARCH_PATHS = /usr/include/libxml2;
- OTHER_LDFLAGS = "-lxml2";
+ IPHONEOS_DEPLOYMENT_TARGET = 2.2.1;
+ "OTHER_LDFLAGS[sdk=iphoneos*][arch=*]" = "$(DEVELOPER_DIR)/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS2.2.1.sdk/usr/lib/libxml2.dylib";
+ "OTHER_LDFLAGS[sdk=iphonesimulator*][arch=*]" = "-lxml2";
PREBINDING = NO;
"PROVISIONING_PROFILE[sdk=iphoneos*]" = "56DD5709-6F51-455B-B301-C65B856A0F8C";
- SDKROOT = iphoneos2.1;
+ SDKROOT = iphoneos3.1.2;
};
name = Distribution;
};
@@ -731,17 +733,19 @@
buildSettings = {
ADDITIONAL_SDKS = "";
ARCHS = "$(ARCHS_STANDARD_32_BIT)";
- "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer: Katsumi Kishikawa";
+ "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
GCC_C_LANGUAGE_STANDARD = c99;
GCC_PREPROCESSOR_DEFINITIONS = DEBUG;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
HEADER_SEARCH_PATHS = /usr/include/libxml2;
+ IPHONEOS_DEPLOYMENT_TARGET = 2.2.1;
ONLY_ACTIVE_ARCH = YES;
- OTHER_LDFLAGS = "-lxml2";
+ "OTHER_LDFLAGS[sdk=iphoneos*][arch=*]" = "$(DEVELOPER_DIR)/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS2.2.1.sdk/usr/lib/libxml2.dylib";
+ "OTHER_LDFLAGS[sdk=iphonesimulator*][arch=*]" = "-lxml2";
PREBINDING = NO;
- "PROVISIONING_PROFILE[sdk=iphoneos*]" = "F064D1B5-1E56-48D6-B621-293C692A49CE";
- SDKROOT = iphoneos2.1;
+ "PROVISIONING_PROFILE[sdk=iphoneos*]" = "";
+ SDKROOT = iphoneos3.1.2;
};
name = Debug;
};
@@ -750,16 +754,18 @@
buildSettings = {
ADDITIONAL_SDKS = "";
ARCHS = "$(ARCHS_STANDARD_32_BIT)";
- "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer: Katsumi Kishikawa";
+ "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
GCC_C_LANGUAGE_STANDARD = c99;
GCC_GENERATE_DEBUGGING_SYMBOLS = NO;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
HEADER_SEARCH_PATHS = /usr/include/libxml2;
- OTHER_LDFLAGS = "-lxml2";
+ IPHONEOS_DEPLOYMENT_TARGET = 2.2.1;
+ "OTHER_LDFLAGS[sdk=iphoneos*][arch=*]" = "$(DEVELOPER_DIR)/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS2.2.1.sdk/usr/lib/libxml2.dylib";
+ "OTHER_LDFLAGS[sdk=iphonesimulator*][arch=*]" = "-lxml2";
PREBINDING = NO;
- "PROVISIONING_PROFILE[sdk=iphoneos*]" = "F064D1B5-1E56-48D6-B621-293C692A49CE";
- SDKROOT = iphoneos2.1;
+ "PROVISIONING_PROFILE[sdk=iphoneos*]" = "";
+ SDKROOT = iphoneos3.1.2;
};
name = Release;
};
View
2  HatenaTouch_Prefix.pch
@@ -6,3 +6,5 @@
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#endif
+
+#define IPHONE_OS_VERSION ([[[UIDevice currentDevice] systemVersion] floatValue])
Please sign in to comment.
Something went wrong with that request. Please try again.