2012-01-16 8 views
1

私たちのビジネスはJavaから切り換えられたので、Objective Cの新機能です。Objective-CFundamentals.pdf電子書籍Christopher K. Fairbairn 、Johannes Fahrenkrug、Collin RuffenachObjective C電子書籍の学習、コードエラー(noob)

しかし、私は多くの問題を抱えています。なぜなら、この本はiPhone 4.3に基づいており、最新のxcodeは5であり、私の仕事で必要とするからです。誰かが私が高く評価されるのを助けることができれば(私はつまらなく)1つの問題(それはとてもシンプルなようです)。

ありがとうございます! :)

編集:私は電子ブックの例から直接コードコードを投稿するので、それは私がこのエラーを与える手紙に電子書籍に従ったが、私はそれをタイプしていないそしてそこに電子書籍の内側にそれを解決する上で助け無し:(しかし迅速な応答をありがとう!

RootMasterViewControler.h

#import <UIKit/UIKit.h> 

@interface RootMasterViewController : UITableViewController { 
NSDictionary *cityMappings; 
} 

@end 

typedef enum PropertyType { 
Unit, 
TownHouse, 
Mansion 
} PropertyType; 

typedef struct { 
NSString *address; 
PropertyType type; 
double weeklyRentalPrice; 
} RentalProperty; 

RootMasterViewControler.m

- (NSInteger)tableView:(UITableView *)tableView 
numberOfRowsInSection:(NSInteger)section { 

return ARRAY_SIZE(properties); 
} 


- (UITableViewCell *)tableView:(UITableView *)tableView 
    cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
static NSString *CellIdentifier = @"Cell"; 
UITableViewCell *cell = [tableView 
         dequeueReusableCellWithIdentifier:CellIdentifier]; 
if (cell == nil) { 
    cell = [[[UITableViewCell alloc] 
      initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier]autorelease]; 
} 
RentalProperty *details = &properties[indexPath.row]; 
int indexOfComma = [details->address rangeOfString:@","].location; 
NSString *address = [details->address 
         substringToIndex:indexOfComma]; 
NSString *city = [details->address 
        substringFromIndex:indexOfComma + 2]; 
cell.textLabel.text = address; 
if ([city isEqual:@"Clifton"]) 
    cell.imageView.image = [UIImage imageNamed:@"mountain.png"]; 
else if ([city isEqual:@"Sumner"]) 
    cell.imageView.image = [UIImage imageNamed:@"sea.png"]; 
else 
    cell.imageView.image = [UIImage imageNamed:@"city.png"]; 
cell.detailTextLabel.text = 
[NSString stringWithFormat:@"Rents for $%0.2f per week", 
details->weeklyRentalPrice]; 
return cell; 
} 

エラー1)@ *アドレス "期待される表現" エラー2)@ cell.textLabel.text "宣言されていない識別子のアドレスの使用

私はObj-Cについては何も知らず、手紙にCを学ぶ電子書籍。助けてくれてありがとう。

http://imageshack.us/photo/my-images/252/screenshot20120113at443.png/

+0

_code_とエラーメッセージをコピー&ペーストしてください。これは、将来この問題が発生する可能性がある他の人にとっては、完全に見分けがつきません。 – sarnold

+0

素早い回答をいただきありがとうございます。コードで質問を編集しました。 –

+0

@ Galaxas0 below:eBookはiOS 4.3のベースについて説明していますが、iOS 5を選択したxcode IDEを使用しています。 –

答えて

0

あなたはそれがCの構造体だったアドレスのような>詳細 - 呼び出すことはできません。 Objective-CオブジェクトはC構造体以上のものです。 setter/getter /プロパティが宣言されている場合は[details getAddress]、詳細クラスのアドレスにアクセスする場合はdetails.addressを使用する必要があります。

第2に、RentalProperty * details = &プロパティ[indexPath.row]を宣言することはできません。これは、参照を格納するポインタを要求しているためです。 &を削除する必要があります。やはり、Objective-CオブジェクトはC構造体よりはるかに多くあります。

3番目に、iOS 4.3に基づいて説明されているが、iOSの最新バージョンは5であると言っても過言ではない。あなたはXcodeの最新バージョンであるXcodeはIDEで、iOSはモバイルOSだ。

関連する問題