Custom TableView Cell Creation with dynamic number of objects

Hello dear programmers,

I have a requirement for creating a custom tableviewcell with a method below:

@interface CustomTableCell : UITableViewCell {

}

@implementation CustomTableCell

-(void)setObjectWithType:(NSString *)objectType atPlace:(CGRect) placeOfObject
{
    class className=NSClassFromString(objectType);

    className *objectName = [[NSClassFromString(objectType) alloc] init];// Giving error    
}

Please solve this issue to create any type of object by passing the arguments like below:

CustomTableCell *cell=[[CustomTableCell alloc] init];
[cell setObjectWithType:@"UILabel" atPlace:CGRectMake(0, 0, 100, 30)];

Thanks, in advance.

Answers


This sounds like it could turn into a nightmare down the line, but to solve your immediate problem, you'd have to use id or the lowest common superclass (e.g. UIView) when creating your arbitrary objects:

id objectName = [[NSClassFromString....

The compiler can't cast dynamically the way you are attempting. It has to be done at runtime.


Need Your Help

C: bit operations on a variable-length bit string

c bit-manipulation bit

I'm doing some bit operations on a variable-length bit string.

How can I check to make sure a window is being actively used, and if not alert the end user that they are about to be logged out?

javascript session

Working on a new back end system for my company, and one of their requests is for a window to become locked down and for the user to be sent to the login screen if they leave it idle for to long.