iPhone_SDK のバックアップソース(No.5) - アールメカブ

アールメカブ


iPhone_SDK のバックアップソース(No.5)

[[Programming]]

iPhone SDK メモ

スタンフォード大で [[iPhone 開発講座とコード:http://www.appbank.net/2008/10/30/iphone-news/1100.php]]が公開されていたらしいが,今は削除されている.
* テーブルのグループ化と配列 [#lc850e3e]

 return [[ array objectAtIndex:section] count]

 cex.text =  [[ array objectAtIndex:indexPath.section]
                        objectAtIndex:indexPath.row]
 return cell;

でいけるだろう。

[[こういう方法:http://icodeblog.com/2008/08/08/iphone-programming-tutorial-populating-uitableview-with-an-nsarray/]]も紹介されている.

* 文字列から改行記号を取る. [#m0c7d174]
[[componentsSeparatedByString:http://www.oomori.com/cocoafw/Foundation/NSString/componentsSeatedByString.html]]関数が指定されたトークンで文字列を区切って配列を返すので,とりあえずこうする.

 string = [[string componentsSeparatedByString:@"\n"] 
            objectAtIndex:0];

ただし "\n" は Macintoshではoptions キーを押しながら円マークで入力

* intValueの[[エラー処理:http://www.gnu-darwin.org/www001/ports-1.5a-CURRENT/deskutils/etoile-systemconfig/work/Etoile/Frameworks/OgreKit/Source/RegularExpression/OGRegularExpressionFormatter.m]] [#m7be4e64]
 int syntaxType = [anObject intValue];
	if (syntaxType == -1) {
		// エラー。例外を発生させる。
		[self release];
		[NSException 
 raise:NSInvalidUnarchiveOperationException format:
   @"fail to  decode"];
	}

* UITableViewにチェックを入れる。 [#mbfab8fe]

[[さまざまな情報:http://developer.apple.com/iphone/library/documentation/UserExperience/Conceptual/TableView_iPhone/ManageSelections/ManageSelections.html]]があって錯綜している。[[ここ:http://www.iphonedevsdk.com/forum/iphone-sdk-development/7391-uitableviewcell-repeat-every-12-rows.html]]にも長い議論があるが、とりあえずは[[ここにあるよう:http://idevkit.com/forums/general-sdk/245-table-view-selection-sign.html]]に使ってみる。

と思ったが,うまくいかないので,チェックしたセクションと行を配列に記憶させ,テーブルがクリックされるたびに [tableView reloadData] で初期化を行うことにした.reloadData 処理には,いろいろ問題もあるようであるが,今のところ,ちゃんと動いている.



>
Now i have another problem, when i select one and i scroll down. I see that some others are selected to.
A bit strange.
<

>
You must be using a reuseIdentifier. When you go to return a cell, make sure to set it's accessoryType to the one without the checkmark unless you know it should be checked.
<

 - (NSIndexPath *)tableView:(UITableView *)tableView  
  didSelectRowAtIndexPath:(NSIndexPath *)indexPath
 {
	SeismicXMLAppDelegate *appDelegate = 
  (SeismicXMLAppDelegate *)[[UIApplication sharedApplication]
                      delegate];
	[appDelegate showEarthquakeInfo:
             [(TableViewCell *)[tableView 
                cellForRowAtIndexPath:indexPath] quake]];
	[[tableView cellForRowAtIndexPath: oldIndexPath] 
                setAccessoryType:UITableViewCellAccessoryNone];
	[[tableView cellForRowAtIndexPath: indexPath] 
               setAccessoryType:UITableViewCellAccessoryCheckmark];
 
        oldIndexPath = indexPath;
	return nil;
 }

 - (UITableViewCell *)tableView:(UITableView *)tableView 
  cellForRowAtIndexPath:(NSIndexPath *)indexPath {
	static NSString *MyIdentifier = @"MyIdentifier";
	
	TableViewCell *cell = (TableViewCell *)[tableView 
               dequeueReusableCellWithIdentifier:MyIdentifier];
	if(indexPath == oldIndexPath){
		cell.accessoryType = 
                    UITableViewCellAccessoryCheckmark;
	}else{
		cell.accessoryType = UITableViewCellAccessoryNone;
 
	}
	if (cell == nil) {
		cell = [[[TableViewCell alloc] 
           initWithFrame:CGRectZero reuseIdentifier:MyIdentifier] 
           autorelease];
		
	}
    
    // Set up the cell.
	SeismicXMLAppDelegate *appDelegate = 
 (SeismicXMLAppDelegate *)[[UIApplication sharedApplication] 
 delegate];
      
    // If the RSS feed isn't accessible (which could happen if
  the network isn't available), show an informative
    // message in the first row of the table.
	if ([appDelegate isDataSourceAvailable] == NO) {
        cell = [[[UITableViewCell alloc] initWithFrame:
          CGRectZero reuseIdentifier:@"DefaultTableViewCell"] 
             autorelease];
        cell.text = NSLocalizedString(@"RSS Host Not Available",
                 @"RSS Host Not Available message");
		cell.textColor = [UIColor colorWithWhite:0.5
         alpha:0.5];
		cell.accessoryType = UITableViewCellAccessoryNone;
		return cell;
	}
	
	Earthquake *quakeForRow = [appDelegate 
              objectInListAtIndex:indexPath.row];
    [cell setQuake:quakeForRow];
	return cell;
 }
- [[あるいは:http://gist.github.com/raw/68574/28fef56d2f1cc594429efa0d18783df686cb3ee0/SelectionListViewController.m]]
 - (UITableViewCell *)tableView:(UITableView *)tableView 
  cellForRowAtIndexPath:(NSIndexPath *)indexPath {
	
	static NSString *SelectionListCellIdentifier = 
           @"SelectionListCellIdentifier";
	
	UITableViewCell *cell = [tableView 
    dequeueReusableCellWithIdentifier:SelectionListCellIdentifier];
	if (cell == nil) {
		cell = [[[UITableViewCell alloc] 
                     initWithFrame:CGRectZero 
        reuseIdentifier:SelectionListCellIdentifier] autorelease];
	}
	
	NSUInteger row = [indexPath row];
	NSUInteger oldRow = [lastIndexPath row];
	cell.text = [list objectAtIndex:row];
	cell.accessoryType = (row == oldRow && lastIndexPath != 
          nil) ? UITableViewCellAccessoryCheckmark : 
                        UITableViewCellAccessoryNone;
	
	return cell;
 }

 - (void)tableView:(UITableView *)tableView 
          didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
	
	int newRow = [indexPath row];
	int oldRow = [lastIndexPath row];
	
	if (newRow != oldRow) {
		UITableViewCell *newCell = [tableView 
                      cellForRowAtIndexPath:indexPath];
		newCell.accessoryType = 
                      UITableViewCellAccessoryCheckmark;
		
		UITableViewCell *oldCell = [tableView 
                     cellForRowAtIndexPath: lastIndexPath]; 
		oldCell.accessoryType = 
                       UITableViewCellAccessoryNone;
		
		lastIndexPath = indexPath;  
	}
	
	[tableView deselectRowAtIndexPath:indexPath
                        animated:YES];
 }