Showing posts with label UITableViewCell. Show all posts
Showing posts with label UITableViewCell. Show all posts

Thursday, April 4, 2013

dequeueReusableCellWithIdentifier:forIndexPath:

iOS 6-ban jelent meg a regi dequeueReusableCellWithIdentifier: mellett es ahogy a doksiban is kiemelik
Important: You must register a class or nib file using the registerNib:forCellReuseIdentifier: or registerClass:forCellReuseIdentifier: method before calling this method.

Azaz vagy marad a regi modszer ami akar 2-es iOS-en is mukodik:
- (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];
    }
return cell;
}


Vagy ha minimum 6-oson hasznaljuk akkor:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
    
    return cell;
}

de ilyenkor fontos, hogy a viewDidLoad-ba betegyuk ezt:
[self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"Cell"];




Tuesday, July 12, 2011

nev-ertek megjelenitese UITableViewCell-ben

Kellett egy olyan UITableViewCell amiben nev-ertek parokat mutatok. Valamiert custom UITableViewCell-t csinaltam erre amibe tettem 2 UILabel-t ahelyett, hogy siman UITableViewCellStyleValue2-vel hoztam volna letre a cellakat. Most kijavitottam, de van par dolog amire itt is oda kell figyelni:

Az egyik dolog, hogy mivel a detailTextLabel-be esetleg tobb sornyi szoveg is kerulhet amit nem akarok trunc-olni ezert a cella magassagat be kell allitani (nem allitja magatol a device) valahogy igy:

- (CGFloat)tableView:(UITableView *)tableView_ heightForRowAtIndexPath:(NSIndexPath *)indexPath {
CGFloat kMinCellHeight = 44.0;
NSString *text = ZXGetPropertyValueForRow([indexPath row]);
CGSize textSize = CGSizeMake(tableView_.frame.size.width - 120.0, FLT_MAX);
CGSize size = [text sizeWithFont:[UIFont systemFontOfSize:15.0f] constrainedToSize:textSize lineBreakMode:UILineBreakModeWordWrap];
size.height += 25.0f;
return MAX(size.height, kMinCellHeight);
}

Azert hasznalom tableView.frame.size.width-120.0-at es nem a tobb helyen ajanlott 200.0f koruli ertekek valamelyiket, mert ez landscape modban is jo lesz. Ha a cella accessoryType-ja nem UITableViewCellAccessoryTypeNone hanem UITableViewCellAccessoryTypeDisclosureIndicator akkor inkabb -140.0-et kell hasznalni, mert a disclosureIndicator (>) elvesz 20 pixelt a detailTextView-tol. Ezek a 120.0-140.0-es ertekek csak hozzavetoleg jok. Azt meg nem sikerult kideriteni, hogy peldaul a Contacts App-ban ha felveszek egy tobb soros notes-ot akkor hogyan csinalja meg pontosan a cella magassagat. (Pedig ez lenne a lenyeg.)
A 25.0f-es ertek pedig ugy jott ki, hogy megneztem milyen magas a cella, ha nem varialok semmit es sorok_szama*19.0+25.0 jott ki azaz az egy soros ertekeknel 44.0f. Kivetel ez alol a Group-ok elso es utolso sora, ahol 45.0f-es a default magassag. (Csak Grouped Style-os UITableView-nal neztem ezeket az ertekeket.) Az elso es utolso sorok magassagat meg hiaba is allitottam 44.0-re, az minimum 45.0 lett.
A 15.0f-es meretet pedig a systemFontOfSize-nal pedig tobb helyen olvastam es probalgatassal nekem is ez jott ki.
Ahhoz persze, hogy tobb soros legyen a detailTextLabel meg be kellett allitani a numberOfLines-t 0-ra.


Egy masik problema volt, hogy a textLabel-be pont nem fert bele amit bele akartam irni. Eloszor azzal probalkoztam, hogy textLabel-en beallitom a betumeretet a setFont-tal ([[cell textLabel] setFont:[UIFont fontWithName:@"Helvetica-Bold" size:12]];), de nem akartam azokat megvaltoztatni amik a default font-tal is elfernenek.
Egy masik megoldas, hogy textLabel-re is beallitjuk a numberOfLines-t mondjuk 0-ra, de mivel a textLabel es a detailTextLabel betumerete nem ugyanakkora ezert ha mindketto 2 soros akkor a masodik soruk el van csuszva egymastol ami eleg benan nez ki.
Vegul azt valasztottam (ami nem tul hosszu szovegeknel mukodik), hogy a numberOfLines-t hagytam a default 1-en (ez fontos!) es beallitottam a minimumFontSize-ot (ami a textLabel-nel kb 12) 10-re. Igy ami elozoleg pont nem fert bele azt meg beleferthet es nem is lesz tul csunya. Ehhez be kell allitani az adjustFontSizeToFitWidth-et is true-ra.
[[cell textLabel] setAdjustsFontSizeToFitWidth:true];
[[cell textLabel] setMinimumFontSize:10.0];

Tuesday, January 25, 2011

Csak az egyik cella ne legyen kijelolve touch-nal

Magan a UITableView-n bekapcsolhatjuk a "Show Selection On Touch"-ot az IB-ben, de ha az egyik cellanal megsem akarunk selection-t, akkor amikor azt letrehozzuk a tableView:cellForRowAtIndexPath:-ban akkor be kell allitani rajta a UITableViewCellSelectionStyleNone-t:
[cell setSelectionStyle:UITableViewCellSelectionStyleNone];

Friday, September 10, 2010

Async kep betoltes UITableViewCell-be

Itt van az Apple peldakodja:
This sample demonstrates a multi-stage approach to loading and displaying a UITableView. It begins by loading the relevant text from an RSS feed so the table can load as quickly as possible, and then downloads the images for each row asynchronously so the UI is more responsive

vagy

Thursday, April 1, 2010

copy + paste > 2 release ugyanazon > EXC_BAD_ACCESS

Arra rajottem, hogy valahol 2 release volt, de azt valamiert nehezen talaltam meg, hogy a custom UITableViewCell dealloc-jaban csinaltam ezt. Igy utolag persze mar tok egyertelmu.

Monday, January 4, 2010

UITableViewCell mozgatasa

Ha atvaltunk edit mode-ba, akkor meg nem tudjuk mozgatni a cellakat, ha nem implementaltuk (akar uresen) a tableView:moveRowAtIndexPath:toIndexPath methodot.

Ha nem akarjuk, hogy az osszes cella mozgathato legyen, akkor meg kell irni a tableView:canMoveRowAtIndexPath method-ot is.

Ha pedig nem szeretnenk, hogy akarhova at lehessen mozgatni akkor a tableView:targetIndexPathForMoveFromRowAtIndexPath:toProposedIndexPath method-ot.

Thursday, October 29, 2009

Cell Styles

Ilyenek vannak:

UITableViewCellStyleDefault

A simple style for a cell with a text label (black and left-aligned) and an optional image view. Note that this is the default style for cells prior to iPhone OS 3.0.

Available in iPhone OS 3.0 and later.

Declared in UITableViewCell.h.

UITableViewCellStyleValue1

A style for a cell with a label on the left side of the cell with left-aligned and black text; on the right side is a label that has smaller blue text and is right-aligned. The Settings application uses cells in this style.

Available in iPhone OS 3.0 and later.

Declared in UITableViewCell.h.

UITableViewCellStyleValue2

A style for a cell with a label on the left side of the cell with text that is right-aligned and blue; on the right side of the cell is another label with smaller text that is left-aligned and black. The Phone/Contacts application uses cells in this style.

Available in iPhone OS 3.0 and later.

Declared in UITableViewCell.h.

UITableViewCellStyleSubtitle

A style for a cell with a left-aligned label across the top and a left-aligned label below it in smaller gray text. The iPod application uses cells in this style.

Available in iPhone OS 3.0 and later.

Declared in UITableViewCell.h.

Discussion

In all these cell styles, the larger of the text labels is accessed via the textLabel property and the smaller via the detailTextLabel property.

Thursday, September 3, 2009

UITableViewCell beszurasa UITableView-ba

Igy szurunk be egy cellat a TableView elejere:

[self.tableView insertRowsAtIndexPaths:myObject withRowAnimation:UITableViewRowAnimationFade];


Igy pedig feltekerunk, hogy lassuk az uj cellat:

[self.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] atScrollPosition:UITableViewScrollPositionTop animated:YES];


Wednesday, August 12, 2009

thumbnail betoltese UITableViewCell-be

Kell egy custom UITableViewCell aminek van egy UIImageView propertyje
pl.:

IBOutlet UIImageView *image;

...

@property (nonatomic, retain) IBOutlet UIImageView *image;


Es ebbe igy lehet betolteni egy kepet file-bol, ha tudjuk hol van:

NSString *filePath = ...;


[[cell image] setImage:[[UIImage alloc] initWithContentsOfFile:filePath]];