How to add different cell to tableview?What's the difference between the atomic and nonatomic attributes?How to detect tableView cell touched or clicked in swiftExpand and Collapse tableview cellsHow to give different tags to buttons in different TableView cells in SwiftTableView not displaying text with JSON data from API callI am trying to append a message for my tableview but it is not appending.please help meNest a UIScrollView in SwiftHow Can I Fetch Sub Category From Rest Api(Restkit) Using Expandable Tableview Cell Swift 3Swift vertical UICollectionView inside UITableViewHow to search in Firebase Database Swift

Is the order of words purely based on convention?

I transpose the source code, you transpose the input!

Is there an equivalent of cash transportation in air cargo?

Is a Middle Name a Given Name?

What should I consider when deciding whether to delay an exam?

An impressive body of work

Smallest number containing the first 11 primes as sub-strings

One-digit products in a row of numbers

Why isn't there armor to protect from spells in the Potterverse?

If a spaceship ran out of fuel somewhere in space between Earth and Mars, does it slowly drift off to the Sun?

Is there any exception that proves or suggests that the law of non-contradiction does not always apply?

What makes learning more difficult as we age?

Is it ok if I haven't decided my research topic when I first meet with a potential phd advisor?

Why would an airline put 15 passengers at once on standby?

Notebook with version-dependent cells

What would influence an alien race to map their planet in a way other than the traditional map of the Earth

Why is the Common Agricultural Policy unfavourable to the UK?

Neural network vs regression in a small sample

Why does C++ have 'Undefined Behaviour' and other languages like C# or Java don't?

How to convert what I'm singing to notes

Delete n lines skip 1 line script

Garage door sticks on a bolt

Shorten leader-line for labels with geometry-generator

How to prevent pickpocketing in busy bars?



How to add different cell to tableview?


What's the difference between the atomic and nonatomic attributes?How to detect tableView cell touched or clicked in swiftExpand and Collapse tableview cellsHow to give different tags to buttons in different TableView cells in SwiftTableView not displaying text with JSON data from API callI am trying to append a message for my tableview but it is not appending.please help meNest a UIScrollView in SwiftHow Can I Fetch Sub Category From Rest Api(Restkit) Using Expandable Tableview Cell Swift 3Swift vertical UICollectionView inside UITableViewHow to search in Firebase Database Swift






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















I have a tableview and I'm downloading data from firebase after that I reload tableview but I want to add more different cell to tableview too. For example my datas count is six and I want to add to second row and fifth row different cell. In the end I want to show eight cell.



I tried this code;



func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int 
return data?.count ?? 0


func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
if indexPath.row == 1
let cell = myTableView.dequeueReusableCell(withIdentifier: "makeLiveWallpaper") as! LiveWallTableViewCell
if indexPath.row == 1
cell.titleLabel.text = "Let's make LiveWallpaper"

return cell
else
if let cell = myTableView.dequeueReusableCell(withIdentifier: "CategoryTableViewCell", for: indexPath) as? CategoryTableViewCell
cell.category = category(at: indexPath)
cell.delegate = self
cell.setScrollPosition(x: offsets[indexPath] ?? 0)
return cell


return UITableViewCell()


func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat
if indexPath.row == 1
return 140
else
return 255




But it is not adding new cell it is over write on cell










share|improve this question
































    0















    I have a tableview and I'm downloading data from firebase after that I reload tableview but I want to add more different cell to tableview too. For example my datas count is six and I want to add to second row and fifth row different cell. In the end I want to show eight cell.



    I tried this code;



    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int 
    return data?.count ?? 0


    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
    if indexPath.row == 1
    let cell = myTableView.dequeueReusableCell(withIdentifier: "makeLiveWallpaper") as! LiveWallTableViewCell
    if indexPath.row == 1
    cell.titleLabel.text = "Let's make LiveWallpaper"

    return cell
    else
    if let cell = myTableView.dequeueReusableCell(withIdentifier: "CategoryTableViewCell", for: indexPath) as? CategoryTableViewCell
    cell.category = category(at: indexPath)
    cell.delegate = self
    cell.setScrollPosition(x: offsets[indexPath] ?? 0)
    return cell


    return UITableViewCell()


    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat
    if indexPath.row == 1
    return 140
    else
    return 255




    But it is not adding new cell it is over write on cell










    share|improve this question




























      0












      0








      0








      I have a tableview and I'm downloading data from firebase after that I reload tableview but I want to add more different cell to tableview too. For example my datas count is six and I want to add to second row and fifth row different cell. In the end I want to show eight cell.



      I tried this code;



      func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int 
      return data?.count ?? 0


      func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
      if indexPath.row == 1
      let cell = myTableView.dequeueReusableCell(withIdentifier: "makeLiveWallpaper") as! LiveWallTableViewCell
      if indexPath.row == 1
      cell.titleLabel.text = "Let's make LiveWallpaper"

      return cell
      else
      if let cell = myTableView.dequeueReusableCell(withIdentifier: "CategoryTableViewCell", for: indexPath) as? CategoryTableViewCell
      cell.category = category(at: indexPath)
      cell.delegate = self
      cell.setScrollPosition(x: offsets[indexPath] ?? 0)
      return cell


      return UITableViewCell()


      func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat
      if indexPath.row == 1
      return 140
      else
      return 255




      But it is not adding new cell it is over write on cell










      share|improve this question
















      I have a tableview and I'm downloading data from firebase after that I reload tableview but I want to add more different cell to tableview too. For example my datas count is six and I want to add to second row and fifth row different cell. In the end I want to show eight cell.



      I tried this code;



      func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int 
      return data?.count ?? 0


      func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
      if indexPath.row == 1
      let cell = myTableView.dequeueReusableCell(withIdentifier: "makeLiveWallpaper") as! LiveWallTableViewCell
      if indexPath.row == 1
      cell.titleLabel.text = "Let's make LiveWallpaper"

      return cell
      else
      if let cell = myTableView.dequeueReusableCell(withIdentifier: "CategoryTableViewCell", for: indexPath) as? CategoryTableViewCell
      cell.category = category(at: indexPath)
      cell.delegate = self
      cell.setScrollPosition(x: offsets[indexPath] ?? 0)
      return cell


      return UITableViewCell()


      func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat
      if indexPath.row == 1
      return 140
      else
      return 255




      But it is not adding new cell it is over write on cell







      ios swift tableview swift4






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 28 at 19:10









      Bhaumik

      9131 gold badge6 silver badges17 bronze badges




      9131 gold badge6 silver badges17 bronze badges










      asked Mar 28 at 19:02









      Sadi HakanSadi Hakan

      421 silver badge11 bronze badges




      421 silver badge11 bronze badges

























          1 Answer
          1






          active

          oldest

          votes


















          1
















          Once you got the data update your dataSource like given below:



          data.insert("", at: 1)
          data.insert("", at: 4)
          self.tableView.reloadData()



          update your Data Source Method




          func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell 
          if indexPath.row == 1
          // your custom Cell
          return cell
          else if indexPath.row == 5
          // you custom Cell
          return cell
          else
          // normal cell

          return UITableViewCell()



          Hope it will hep you.






          share|improve this answer



























          • but data is a struck it says "Cannot convert value of type 'String' to expected argument type 'Category'"

            – Sadi Hakan
            Mar 28 at 19:22











          • @SadiHakan "" is for sample here you have to add your Category object in the array.

            – Muhammad Waqas Bhati
            Mar 28 at 19:24











          • @SadiHakan it's solved or not ?

            – Muhammad Waqas Bhati
            Mar 28 at 19:31











          • yes it is solved thx

            – Sadi Hakan
            Mar 28 at 20:03













          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );














          draft saved

          draft discarded
















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55405096%2fhow-to-add-different-cell-to-tableview%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1
















          Once you got the data update your dataSource like given below:



          data.insert("", at: 1)
          data.insert("", at: 4)
          self.tableView.reloadData()



          update your Data Source Method




          func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell 
          if indexPath.row == 1
          // your custom Cell
          return cell
          else if indexPath.row == 5
          // you custom Cell
          return cell
          else
          // normal cell

          return UITableViewCell()



          Hope it will hep you.






          share|improve this answer



























          • but data is a struck it says "Cannot convert value of type 'String' to expected argument type 'Category'"

            – Sadi Hakan
            Mar 28 at 19:22











          • @SadiHakan "" is for sample here you have to add your Category object in the array.

            – Muhammad Waqas Bhati
            Mar 28 at 19:24











          • @SadiHakan it's solved or not ?

            – Muhammad Waqas Bhati
            Mar 28 at 19:31











          • yes it is solved thx

            – Sadi Hakan
            Mar 28 at 20:03















          1
















          Once you got the data update your dataSource like given below:



          data.insert("", at: 1)
          data.insert("", at: 4)
          self.tableView.reloadData()



          update your Data Source Method




          func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell 
          if indexPath.row == 1
          // your custom Cell
          return cell
          else if indexPath.row == 5
          // you custom Cell
          return cell
          else
          // normal cell

          return UITableViewCell()



          Hope it will hep you.






          share|improve this answer



























          • but data is a struck it says "Cannot convert value of type 'String' to expected argument type 'Category'"

            – Sadi Hakan
            Mar 28 at 19:22











          • @SadiHakan "" is for sample here you have to add your Category object in the array.

            – Muhammad Waqas Bhati
            Mar 28 at 19:24











          • @SadiHakan it's solved or not ?

            – Muhammad Waqas Bhati
            Mar 28 at 19:31











          • yes it is solved thx

            – Sadi Hakan
            Mar 28 at 20:03













          1














          1










          1









          Once you got the data update your dataSource like given below:



          data.insert("", at: 1)
          data.insert("", at: 4)
          self.tableView.reloadData()



          update your Data Source Method




          func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell 
          if indexPath.row == 1
          // your custom Cell
          return cell
          else if indexPath.row == 5
          // you custom Cell
          return cell
          else
          // normal cell

          return UITableViewCell()



          Hope it will hep you.






          share|improve this answer















          Once you got the data update your dataSource like given below:



          data.insert("", at: 1)
          data.insert("", at: 4)
          self.tableView.reloadData()



          update your Data Source Method




          func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell 
          if indexPath.row == 1
          // your custom Cell
          return cell
          else if indexPath.row == 5
          // you custom Cell
          return cell
          else
          // normal cell

          return UITableViewCell()



          Hope it will hep you.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Mar 28 at 20:44









          Bhaumik

          9131 gold badge6 silver badges17 bronze badges




          9131 gold badge6 silver badges17 bronze badges










          answered Mar 28 at 19:16









          Muhammad Waqas BhatiMuhammad Waqas Bhati

          2,05714 silver badges23 bronze badges




          2,05714 silver badges23 bronze badges















          • but data is a struck it says "Cannot convert value of type 'String' to expected argument type 'Category'"

            – Sadi Hakan
            Mar 28 at 19:22











          • @SadiHakan "" is for sample here you have to add your Category object in the array.

            – Muhammad Waqas Bhati
            Mar 28 at 19:24











          • @SadiHakan it's solved or not ?

            – Muhammad Waqas Bhati
            Mar 28 at 19:31











          • yes it is solved thx

            – Sadi Hakan
            Mar 28 at 20:03

















          • but data is a struck it says "Cannot convert value of type 'String' to expected argument type 'Category'"

            – Sadi Hakan
            Mar 28 at 19:22











          • @SadiHakan "" is for sample here you have to add your Category object in the array.

            – Muhammad Waqas Bhati
            Mar 28 at 19:24











          • @SadiHakan it's solved or not ?

            – Muhammad Waqas Bhati
            Mar 28 at 19:31











          • yes it is solved thx

            – Sadi Hakan
            Mar 28 at 20:03
















          but data is a struck it says "Cannot convert value of type 'String' to expected argument type 'Category'"

          – Sadi Hakan
          Mar 28 at 19:22





          but data is a struck it says "Cannot convert value of type 'String' to expected argument type 'Category'"

          – Sadi Hakan
          Mar 28 at 19:22













          @SadiHakan "" is for sample here you have to add your Category object in the array.

          – Muhammad Waqas Bhati
          Mar 28 at 19:24





          @SadiHakan "" is for sample here you have to add your Category object in the array.

          – Muhammad Waqas Bhati
          Mar 28 at 19:24













          @SadiHakan it's solved or not ?

          – Muhammad Waqas Bhati
          Mar 28 at 19:31





          @SadiHakan it's solved or not ?

          – Muhammad Waqas Bhati
          Mar 28 at 19:31













          yes it is solved thx

          – Sadi Hakan
          Mar 28 at 20:03





          yes it is solved thx

          – Sadi Hakan
          Mar 28 at 20:03




















          draft saved

          draft discarded















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid …


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55405096%2fhow-to-add-different-cell-to-tableview%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          How to preserve electronics (computers, tablets and phones) for hundreds of years Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) The network's official Twitter account is up and running again. What content…How might modern humans leave a message for 50,000 years?How would an aquatic race develop computers?How do we make computers care for human life?Keeping supplies for 1000 yearsWhat will cell phones become in 100 years?What body armor protects against a laser?Could a society attain 1800s technology if limited to using copper and bronze?Electricity power (magic) and electronicsScavenging metal resources in post-apocalypse after 100 yearsWhy would precursors create devices that can survive and still work after hundreds of years?

          155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해

          해남서초등학교 학교 연혁 학교 동문 외부 링크 둘러보기 메뉴북위 34° 34′ 21″ 동경 126° 35′ 50″ / 북위 34.5726385° 동경 126.5972670°  / 34.5726385; 126.5972670해남서초등학교eh