Re: Assigning to property with 'readonly' atribute not allowed
Re: Assigning to property with 'readonly' atribute not allowed
- Subject: Re: Assigning to property with 'readonly' atribute not allowed
- From: Fritz Anderson <email@hidden>
- Date: Tue, 28 Jun 2011 09:12:02 -0500
On 27 Jun 2011, at 9:52 PM, Fernando Aureliano wrote:
> - (AQGridViewCell *) gridView: (AQGridView *)inGridView cellForItemAtIndex:
> (NSUInteger) index;
> {
> MagazineCell *cell = (MagazineCell *)[inGridView
> dequeueReusableCellWithIdentifier:@"cell"];
> if (!cell) {
> cell = [MagazineCell cell];
> *cell.reuseIdentifier = @"cell";*
> //Assigning to property with 'readonly' atribute not allowed
> }
> cell.backgroundColor = [UIColor clearColor];
> cell.selectionStyle = AQGridViewCellSelectionStyleGlow;
> cell.edicaoLabel.text = [[edicoesArray objectAtIndex:index] name];
> cell.dataLabel.text = [[edicoesArray objectAtIndex:index] name];
> return cell;
> }
>
> I tried to do this on head file
>
> @property(nonatomic, readwrite) NSString * reuseIdentifier;
>
> I also tried
>
> @property(nonatomic, assign) NSString * reuseIdentifier;
>
> But still no work.
In what way was the reply you got yesterday not satisfactory?
The class seems to be modeled on UITableViewCell, in which assignment to the reuse identifier is illegal.
A glance at the class on GitHub suggests the reason: The identifier is intended as a key into an NSMutableDictionary. In general, changing the identifier would require changing the placement of the cell in the dictionary. AQGridViewCell has no reference back to its container, so the change is impossible. Changing reuseIdentifier would break AQGridView.
Redeclaring reuseIdentifier won't change an assignment that can't work into one that can. All it would do is silence the compiler and leave your app to crash. Changing the attribute to "assign" is a particularly bad idea when the intended behavior is "copy." Review the memory-management guide to understand why.
I assume you have control over class MagazineCell, and can initialize it as you please. Why can't you call [super initWithFrame: CGRectZero reuseIdentifier: @"cell"] in its initializer?
— F
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden