月別アーカイブ: 2014年9月

COREDATA

平成26年9月6日

マイグレーション調査

[objc]
//
[newManagedObject setValue:[NSNumber numberWithBool:NO] forKey:@"on_off"];
//
[/objc]

平成26年9月5日

model変更(on_off追加)

[objc]
– (NSPersistentStoreCoordinator *)persistentStoreCoordinator
{
//modelを変更した場合の対処 その①
/*
NSURL *storeURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"WeatherForcaster01.sqlite"];
[[NSFileManager defaultManager] removeItemAtURL:storeURL error:nil];

if (_persistentStoreCoordinator != nil) {
return _persistentStoreCoordinator;
}
*/

//model変更無し

NSURL *storeURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"WeatherForcaster01.sqlite"];

if (_persistentStoreCoordinator != nil) {
return _persistentStoreCoordinator;
}

NSError *error = nil;
_persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]];

//modelを変更した場合の対処 その② 実使用無し
//—————————-
// Check if we already have a persistent store
if ( [[NSFileManager defaultManager] fileExistsAtPath: [storeURL path]] ) {
NSDictionary *existingPersistentStoreMetadata = [NSPersistentStoreCoordinator metadataForPersistentStoreOfType: NSSQLiteStoreType URL: storeURL error: &error];
if ( !existingPersistentStoreMetadata ) {
// Something *really* bad has happened to the persistent store
[NSException raise: NSInternalInconsistencyException format: @"Failed to read metadata for persistent store %@: %@", storeURL, error];
}

if ( ![self.managedObjectModel isConfiguration: nil compatibleWithStoreMetadata: existingPersistentStoreMetadata] ) {
if ( ![[NSFileManager defaultManager] removeItemAtURL: storeURL error: &error] )
NSLog(@"*** Could not delete persistent store, %@", error);
} // else the existing persistent store is compatible with the current model – nice!
} // else no database file yet
//—————————-

if (![_persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:nil error:&error]) {
/*
Replace this implementation with code to handle the error appropriately.

abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.

Typical reasons for an error here include:
* The persistent store is not accessible;
* The schema for the persistent store is incompatible with current managed object model.
Check the error message to determine what the actual problem was.

If the persistent store is not accessible, there is typically something wrong with the file path. Often, a file URL is pointing into the application’s resources directory instead of a writeable directory.

If you encounter schema incompatibility errors during development, you can reduce their frequency by:
* Simply deleting the existing store:
[[NSFileManager defaultManager] removeItemAtURL:storeURL error:nil]

* Performing automatic lightweight migration by passing the following dictionary as the options parameter:
@{NSMigratePersistentStoresAutomaticallyOption:@YES, NSInferMappingModelAutomaticallyOption:@YES}

Lightweight migration will only work for a limited set of schema changes; consult "Core Data Model Versioning and Data Migration Programming Guide" for details.

*/
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
abort();
}

return _persistentStoreCoordinator;
}
[/objc]

UIBUTTON

平成26年9月5日

[objc]
– (void)awakeFromNib
{
// Initialization code
[self.switch_button setImage:[UIImage imageNamed:@"on.png"] forState:UIControlStateSelected];
[self.switch_button setImage:[UIImage imageNamed:@"off.png"] forState:UIControlStateNormal];
switch_button.selected = YES;
//switch_button.selected = NO;
}
[/objc]

searchbar

平成26年9月4日
階層
スクリーンショット 2014-09-04 1.17.31 PM

search Barを使用する場合の措置について

[objc]
– (TableViewCustomCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";

// 重要 Search Barを使用する場合は、self.をtableViewの頭にいれる。
//TableViewCustomCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier ];
TableViewCustomCell *cell = [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier ];
//
//
}
[/objc]

UICOLOR

平成26年9月3日(水曜日)

[objc]
//
_view2.backgroundColor=[UIColor colorWithRed:0.96 green:0.96 blue:0.86 alpha:0.3];
//
[/objc]

[objc]
//
cell.detailTextLabel.textColor = [UIColor greenColor];
//
[/objc]

UIScroll View

平成26年9月2日(火曜日)

  • Scroll View追加
  • その下位にView追加
  • Scroll View→add New constrain (上下左右 0 0 0 0)
  • View→ add New constrain (上下左右 0 0 0 0)
  • View→ width,height設定
  • View→Center X Alignment設定

テーブルビューでカスタムセルを使う。

平成26年9月1日(月曜日)〜

XIBファイル作成
file → new → user interface → empty
uitablebiewcellドラッグ
label ドラッグ
button ドラッグ
設定 custom
設定 identifier Cell

CLASSファイル作成
TableViewCustomCell

両者のリンク
@property (weak, nonatomic) IBOutlet UILabel *str1;
@synthesize str1;

segue設定(showDetail)

UIViewController

[objc]
@property (strong, nonatomic) IBOutlet UITableView *tableView;
[/objc]

TableViewContoroller.m

[objc]
#import TableViewCustomCell.h;
[/objc]

nibにて使用

[objc]
static NSString * const TableViewCustomCellIdentifier = TableViewCustomCell;
[/objc]

viewdidload

[objc]
– (void)viewDidLoad
{
[super viewDidLoad];
// カスタマイズしたセルをテーブルビューにセット
UINib *nib = [UINib nibWithNibName:TableViewCustomCellIdentifier bundle:nil];
[self.tableView registerNib:nib forCellReuseIdentifier:@"Cell];
//[self.searchDisplayController.searchResultsTableView registerNib:nib forCellReuseIdentifier:@"Cell];
}
[/objc]

cellForRowAtIndexPath

[objc]
// テーブルセル表示① cellForRowAtIndexPath
//- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
– (TableViewCustomCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";

// 重要 カスタムセル
//TableViewCustomCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier ];
TableViewCustomCell *cell = [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier ];

/*
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
*/

if (cell == nil) {
cell = [[TableViewCustomCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier];
}

[self configureCell:cell atIndexPath:indexPath];
return cell;
}
[/objc]

heightForRowAtIndexPath

[objc]
– (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return [TableViewCustomCell rowHeight];
}
[/objc]

didSelectRowAtIndexPath

[objc]
– (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// The table view should not be re-orderable.
//NSLog(@"push");

// セグエで画面遷移させる → prepareForSegueが発生
//prepareForSegueが発生
[self performSegueWithIdentifier:@"showDetail" sender:self.tableView];
}
[/objc]

configureCell

[objc]
– (void)configureCell:(TableViewCustomCell *)cell atIndexPath:(NSIndexPath *)indexPath
{
NSManagedObject *object = [self.fetchedResultsController objectAtIndexPath:indexPath];
//cell.textLabel.text = [[object valueForKey:@"timeStamp"] description];
cell.name.text = [[object valueForKey:@"timeStamp"] description];

}
[/objc]

UIBUTTON

平成26年9月1日(月曜日)

XIB設定(button設定)
TYPE →CUSTOM
STATECONFIG→ SELECTED

TableViewCustomCell.h

[objc]
@property (weak, nonatomic) IBOutlet UIButton *button; @end
[/objc]

 

TableViewCustomCell.m

ボタン押下

[objc]
<pre>- (IBAction)press_button:(UIButton *)sender {

// _button.selected = true;
NSLog(@"press!!");
if (_button.selected == true) {
_button.selected = false;
} else if(_button.selected == false) {
_button.selected = true;
}
}
[/objc]

ON OFF 背景画像切り替え

[objc]
– (void)awakeFromNib
{
// Initialization code
NSLog(@"press!!");
[self.button setImage:[UIImage imageNamed:@"5.png"] forState:UIControlStateNormal];
[self.button setImage:[UIImage imageNamed:@"3.png"] forState:UIControlStateSelected];
}
[/objc]