Ios Swift/UITableView在节中插入随机行以发布AdMob广告

Ios Swift/UITableView在节中插入随机行以发布AdMob广告,ios,swift,tableview,Ios,Swift,Tableview,我希望发布广告。我希望广告位于UITableView中。在常规内容中随机添加。我的UITableView很容易像这样填充: func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return example.count } func tableView(tableView: UITableView, cellForRowAtIndexPath indexPa

我希望发布广告。我希望广告位于
UITableView
中。在常规内容中随机添加。我的
UITableView
很容易像这样填充:

func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {

        return example.count
}

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

        let cell = tableView.dequeueReusableCellWithIdentifier("newEventsCell", forIndexPath: indexPath) as! ExampleCell
        return cell
}
    [regular content]
-------------------------
    [    ad  cell   ]
-------------------------
    [regular content]
-------------------------
    [regular content]
-------------------------
    [regular content]
-------------------------
    [    ad  cell   ]
-------------------------
    [regular content]
-------------------------
如何将
UITableViewCell走私为!AdCell
是否随机进入UITableView?非常感谢你的帮助

例如:

func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {

        return example.count
}

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

        let cell = tableView.dequeueReusableCellWithIdentifier("newEventsCell", forIndexPath: indexPath) as! ExampleCell
        return cell
}
    [regular content]
-------------------------
    [    ad  cell   ]
-------------------------
    [regular content]
-------------------------
    [regular content]
-------------------------
    [regular content]
-------------------------
    [    ad  cell   ]
-------------------------
    [regular content]
-------------------------

您可以创建一个新的原型单元,并使用一个新的标识符(如“Ads”)创建它,然后您只需修改数组,以便有时(随机)添加添加单元,例如,如果您的数组是一个模型,您可以创建一个变量isAnAds,并且在评估要返回的单元时,如果isAnAds为false或“广告“如果isAnAds为真,则为单元格。我使用这种方法在同一个表视图上有两种不同类型的单元格,希望它能有所帮助:D

这里是一个示例代码的图片,为同一个表视图提供了两种不同的单元格类型,这里我的条件只是为了测试,然后是indexath.row==1我在您的canse中使用了Ad单元格,在另一个例子中,我只使用了正常的细胞类型。我今天会试试你的解决方案,让你明白。。。我正在使用我当前的数组“TestArray”(f.e.),里面装满了我想要的内容。并将Ad元素添加到此数组中?你能提供任何类型的代码让你的想法更容易理解吗?图片中的代码决定了拍摄哪个单元格?但是基于什么条件,这只是一个例子,它只是根据它是否是数字1来决定,这意味着是第二个单元格,但是你可以根据你的需要用一个随机范围来决定。