iphone - Horizontal UIScrollView inside a UITableViewCell -


i'm trying create exact same effect in appstore app viewing screenshots: inside uitableview, have custom subclasses of uitableviewcell's. 1 of them designed show previews of product, 4 images. want them show same way appstore presents screenshots of app : inside horizontal uiscrollview attached uipagecontrol.

so add uiscrollview , uipagecontrol uitableviewcell, :

@implementation phvolumepreviewcell - (id)init {     if (self = [super initwithstyle:uitableviewcellstyledefault reuseidentifier:kvolumepreviewcellidentifier]) {         [self setaccessorytype:uitableviewcellaccessorydisclosureindicator];         [self setselectionstyle:uitableviewcellseparatorstylenone];          previews = [[nsmutablearray alloc] initwithcapacity:4];         (int = 0; < 4; i++) {             [previews addobject:@"dummy"];         }          scrollview = [[uiscrollview alloc] initwithframe:cgrectzero];         [scrollview setpagingenabled:yes];         [scrollview setbackgroundcolor:[uicolor graycolor]];         [scrollview setindicatorstyle:uiscrollviewindicatorstyleblack];         [scrollview setshowshorizontalscrollindicator:yes];         [scrollview setbounces:yes];         [scrollview setscrollenabled:yes];         [scrollview setdelegate:self];         [self.contentview addsubview:scrollview];         [scrollview release];          pagecontrol = [[uipagecontrol alloc] initwithframe:cgrectzero];         [pagecontrol setnumberofpages:[previews count]];         [pagecontrol setbackgroundcolor:[uicolor graycolor]];         [self.contentview addsubview:pagecontrol];         [pagecontrol release];     }     return self; } 

(note: i'm populating "previews" dummy data here, in order have [previews count] works ; want view scrollview's scroll indicator test purposes only, i'll hide them later on).

my problem can scroll whole uitableview containing phvolumepreviewcell (subclass of uitableviewcell), can't scroll uiscrollview. how can achieve this?

the information found there: http://theexciter.com/articles/touches-and-uiscrollview-inside-a-uitableview.html talks of old sdks (namely 2.2) , i'm sure there more "recent" approach doing this.

some precisions :

  • i can scroll uiscrollview 2 fingers. that's not want, want able scroll 1 finger only.
  • when scroll 2 fingers, tableview still intercepts touches , scroll little bit top or bottom. i'd tableview stick @ position when touch scrollview.

i believe have work out how intercept touches on tableview, , if touch on phvolumepreviewcell (custom uitableviewcell subclass), pass cell instead of handling on tableview.

for record, tableview created programmatically in uitableviewcontroller subclass:

@interface phvolumecontroller : uitableviewcontroller <uitableviewdelegate> {     locallibrary *lib;         nsstring *volumeid;         llvolume *volume; }  - (id)initwithlibrary:(locallibrary *)newlib andvolumeid:(nsstring *)newvolumeid; @end 

 

@implementation phvolumecontroller  #pragma mark - #pragma mark initialization  - (id)initwithlibrary:(locallibrary *)newlib andvolumeid:(nsstring *)newvolumeid {     if (self = [super initwithstyle:uitableviewstyleplain]) {         lib          = [newlib retain];         volumeid     = newvolumeid;         volume       = [(llvolume *)[llvolume alloc] initfromlibrary:lib forid:volumeid];         [[self navigationitem] settitle:[volume title]];     }     return self; }  - (nsinteger)numberofsectionsintableview:(uitableview *)tableview {     return 1; }  - (nsinteger)tableview:(uitableview *)tableview numberofrowsinsection:(nsinteger)section {     return 1; }  - (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath {     uitableviewcell *cell = [tableview dequeuereusablecellwithidentifier:kvolumepreviewcellidentifier];     if (cell == nil) {         cell = [[[phvolumepreviewcell alloc] init] autorelease];     }      [(phvolumepreviewcell *)cell setvolume:volume];     return (uitableviewcell *)cell; }  - (cgfloat)tableview:(uitableview *)tableview heightforrowatindexpath:(nsindexpath *)indexpath {     return kvolumepreviewcellheight; } 

thanks help!

i have found workaround.

recreating scratch simple uitableview (8 rows), , inserting uiscrollview in second row, works perfectly. nested scroll views (the tableview , scrollview) scroll independently expected. done in single-file test project, in appdelegate.

so... first thought "this might delegation problem", told scrollview delegate tableview, not custom tableviewcell subclass. no avail.

then instead of resorting custom, clean tableviewcell subclass adds scrollview , pagecontrol, resorted creating plain tableviewcell in tableview's cellforrowatindexpath: method. then, create uiscrollview right after initializing tableviewcell, add tableviewcell, , shazam... works!

before:

uitableviewcell *cell = [tableview dequeuereusablecellwithidentifier:kvolumepreviewcellidentifier]; if (cell == nil) {     cell = [[[phvolumepreviewcell alloc] init] autorelease]; }  [(phvolumepreviewcell *)cell setvolume:volume]; // job of creating cell's scrollview , pagecontrol  return (uitableviewcell *)cell 

after:

uitableviewcell *cell = [tableview dequeuereusablecellwithidentifier:kvcpreviewrowidentifier]; if (cell == nil) {     cell = [[[uitableviewcell alloc] initwithstyle:uitableviewcellstyledefault reuseidentifier:kvcpreviewrowidentifier] autorelease];      previewscrollview = [[uiscrollview alloc] initwithframe:cgrectmake(0, 0, tableview.frame.size.width, kvcpreviewscrollviewheight)];     [previewscrollview setcontentsize:cgsizemake(1000, kvcpreviewscrollviewheight)];     [[cell contentview] addsubview:previewscrollview];      previewpagecontrol = [[uipagecontrol alloc] initwithframe:cgrectmake(0, kvcpreviewscrollviewheight, tableview.frame.size.width, kvcpreviewpagecontrolheight)];     [previewpagecontrol setnumberofpages:4];     [[cell contentview] addsubview:previewpagecontrol]; }  return (uitableviewcell *)cell; 

how heck comes when create scrollview tvcell subclass, doesn't play nice ; when create scrollview tableview right after creating "classical" tvcell, works?

i might have found solution, i'm still puzzled reason.


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -