2010-12-28 7 views
0

tableviewcontrollerでセルが選択されている場合、Firstviewcontrollerのイメージを更新する必要があります。 私のアプリケーションのナビゲーションベース。 Firstviewcontrollerにはボタンイベントが含まれています。ボタンをタップ私はテーブルビューを発射しています。テーブルビューでは、私はセルを選択し、左側のチェックマークを更新しています、それは正常に動作しています。私の質問は、セルが選択されていることを示すためにビューコントロール内の別のカスタムイメージを更新する必要があると同時にセルが選択されたときです。 With ref.テーブルビューの中でイメージセルを選択しました。 Firstviewcontrollerに表示する方法テーブルセルがコントローラ外で選択されている場合、カスタムイメージを更新する方法

here it is Appdelegate 

    @interface FertilityAppAppDelegate : NSObject <UIApplicationDelegate> 
    { 
     Fertility *updateImage; 

    } 

    @property (nonatomic, retain) Fertility *updateImage; 

    @implementation 
    @synthesize updateImage; 



    @interface Fertility : UIViewController 
    { 
     UIImageView *imgView; 
     FertilityAppAppDelegate *Appdelegate; 
    } 

    @property(nonatomic,retain) FertilityAppAppDelegate *Appdelegate; 
    @property (nonatomic, retain) UIImageView *imgView; 


Viewcontroller for image update 

    @implementation Fertility 
    @synthesize imgView,Appdelegate; 


    - (void)viewDidLoad 
    { 
     [super viewDidLoad]; 

     Appdelegate = (FertilityAppAppDelegate*)[[UIApplication sharedApplication] delegate]; 
    } 

    - (void)changeImg:(UIImage*)image 
    { 

     imgView.image = image; 
    } 

    - (void)assignObjToTableViewClass 
    { 

     Appdelegate.updateImage = self; 
    } 

Tableview controller 

    @interface Menstruation : UITableViewController 
    { 

     FertilityAppAppDelegate *Appdelegate; 

    } 

    @property (nonatomic, retain) FertilityAppAppDelegate *Appdelegate; 


    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
    { 

     UIImage *image = [UIImage imageNamed:@"bar.png"]; 
     [Appdelegate.updateImage changeImg:image]; 


     selectedRow = indexPath.row; 
     [self.tableView reloadData]; 
    } 


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
     { 

      static NSString *CellIdentifier = @"Cell"; 

       UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
       if (cell == nil) 
      { 

        cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease]; 
       [[cell imageView] setImage:[UIImage imageNamed:@"Tick.png"]]; 

       } 


      [[cell imageView] setHidden:YES]; 

      if (indexPath.row == selectedRow) 
      { 

       [[cell imageView] setHidden:NO]; 
      } 


      NSString *cellValue = [MenstruationArray objectAtIndex:indexPath.row]; 
      cell.text = cellValue; 
      return cell; 

     } 

alt text

。上記の画像はボタンの下に赤色のバーが付いたボタンです。
Firstviewcontrollerでこのボタンをクリックすると、月経テーブルビューで発生すると同時に、私はFirstviewcontrollerにイメージバーを更新する必要があります。

+0

。 – vikingosegundo

答えて

0

別のビューコントローラでイメージを変更する場合は、didSelectRowAtIndexPathメソッドでイメージを割り当てる必要があります。

このため、特定のビューコントローラオブジェクトにアクセスする必要があります(これは、すでに新しいものを使用していない)。

これらのタイプのものについては、チュートリアルはありません。

私はいくつかのコードを送信しますので、そのように従ってください。

まず、AppDelegateClassでImgViewControllerクラスオブジェクトを宣言する必要があります。それで、あなただけが使用できます。

次に、次のコードを使用します。私は理解のためにこのコードを書いています。

@interface ImgViewController : UIViewController{ 
     UIImageView *imgView; 
     AppDelegateClass *delegate; 
} 

@implementation ImgViewController 

- (void)viewDidLoad{ 

    delegate = (AppDelegateClass*)[[UIApplication sharedApplication]delegate]; 
    delegate.imageViewControllerObj = self; // Or you can call the method 
    //[self assignObjToTableViewClass]; 
} 

- (void)changeImg:(UIImage*)image{ 

    imgView.image = image; 
} 

- (void)assignObjToTableViewClass{ 

    delegate.imageViewControllerObj = self; 
} 

@end 

@interface TableViewControllerClass : UIViewController{ 
     AppDelegateClass *delegate; 

} 

@implementation TableViewControllerClass 

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ 
     UIImage *image = //Give what ever image you want to change 
     [delegate.imageViewControllerObj changeImg:image]; 

} 


@end 

よろしく、

サティヤ適切なフォーマットが役立つだろう

+0

別のセルが選択された場合は、新しいイメージを毎回更新する必要があります。私にいくつかのサンプルやチュートリアルを投稿してください – SOF

+0

私はいくつかのコードを追加しました。ご確認ください – Satya

+0

ああ申し訳ありませんが、それはsharedApplicationです。 "d"が見つからない – Satya

関連する問題